1import pytest 2 3from mock import Mock 4from rawkit.options import option, Options, WhiteBalance 5 6 7@pytest.fixture 8def options(): 9 return Options() 10 11 12@pytest.fixture 13def opt_method(): 14 @option() 15 def method(): 16 raise NotImplementedError 17 18 return method 19 20 21def test_calling_an_option_method_directly_should_error(opt_method): 22 with pytest.raises(TypeError): 23 opt_method() 24 25 26def test_setting_a_value(options): 27 # TODO: It would probably be better for these to operate on a Mock and 28 # check if __set__ was called. 29 30 # Uses normal set 31 options.darkness = 1 32 assert options.darkness is 1 33 34 # Uses a special setter 35 options.bps = 16 36 assert options.bps == 16 37 38 39def test_option_from_class_should_return_decorator(): 40 assert type(Options.bps) is option 41 42 43def test_custom_wb_param_writer_writes_rgbg_and_greybox(options): 44 options.white_balance = WhiteBalance(greybox=(7, 7, 7, 7), 45 rgbg=(42, 42, 42, 42)) 46 params = options._map_to_libraw_params(Mock()) 47 48 for v in params.greybox: 49 assert v == 7 50 for v in params.user_mul: 51 assert v == 42 52 53 54def test_bps_must_be_8_or_16(options): 55 with pytest.raises(ValueError): 56 options.bps = 5 57 58 59def test_options_are_iterable(options): 60 options.half_size = True 61 assert 'half_size' in options 62 assert 'bps' not in options 63 64 65def test_options_repr(options): 66 options.half_size = True 67 68 assert repr(options) == repr({'half_size': True}) 69 70 71def test_options_keys(options): 72 options.half_size = True 73 74 assert options.keys() == ['half_size'] 75 76 77def test_options_values(options): 78 options.half_size = True 79 80 assert options.values() == [True] 81 82 83def test_set_rotation_invalid_type(options): 84 with pytest.raises(TypeError): 85 options.rotation = 'fish' 86 87 88def test_set_rotation_value_is_reduced(options): 89 options.rotation = 270 + 90 90 assert options.rotation == 0 91 92 options.rotation = 270 + 180 93 assert options.rotation == 90 94 95 options.rotation = None 96 assert options.rotation is None 97 98 99def test_set_rotation_invalid_value(options): 100 with pytest.raises(ValueError): 101 options.rotation = 93.5 102 103 104def test_rotation_param_writer_values(options): 105 values = { 106 270: 5, 107 180: 3, 108 90: 6, 109 0: 0 110 } 111 for value in values.keys(): 112 options.rotation = value 113 params = options._map_to_libraw_params(Mock()) 114 assert params.user_flip.value == values[value] 115 116 117def test_dark_frame_setter(options): 118 options.dark_frame = 'Some String' 119 assert options._dark_frame == 'Some String' 120 121 122def test_dark_frame_writer(options): 123 options.dark_frame = 'Some String' 124 params = options._map_to_libraw_params(Mock()) 125 assert params.dark_frame.value == b'Some String' 126 127 df = Mock() 128 df._tmp = 'fakefile' 129 df.name = df._tmp 130 options.dark_frame = df 131 params = options._map_to_libraw_params(Mock()) 132 assert params.dark_frame.value == b'fakefile' 133 134 135def test_use_camera_profile_setter(options): 136 options.use_camera_profile = False 137 assert options.use_camera_profile is False 138 139 options.use_camera_profile = True 140 assert options.use_camera_profile is True 141 142 143def test_use_camera_profile_writer(options): 144 options.use_camera_profile = True 145 params = options._map_to_libraw_params(Mock()) 146 assert params.camera_profile.value == b'embed' 147 148 options.use_camera_profile = False 149 params = options._map_to_libraw_params(Mock()) 150 assert params.camera_profile is None 151