def test_map_not_int_flag(flag): with pytest.raises(bitmask.InvalidBitFlag): bitmask.extend_bit_flag_map('DetectorMap', DEAD=flag) with pytest.raises(bitmask.InvalidBitFlag): class ObservatoryDQMap(bitmask.BitFlagNameMap): CR = flag
def test_map_redefine_flag(monkeypatch, caching): monkeypatch.setattr(bitmask, '_ENABLE_BITFLAG_CACHING', caching) class ObservatoryDQMap(bitmask.BitFlagNameMap): _not_a_flag = 8 CR = 1 HOT = 2 DEAD = 4 with pytest.raises(AttributeError): class DetectorMap1(ObservatoryDQMap): __version__ = '1.0' CR = 16 with pytest.raises(AttributeError): class DetectorMap2(ObservatoryDQMap): SHADE = 8 _FROZEN = 16 DetectorMap2.novel = 32 with pytest.raises(AttributeError): bitmask.extend_bit_flag_map( 'DetectorMap', ObservatoryDQMap, READOUT_ERR=16, SHADE=32, readout_err=128 )
def test_map_not_bit_flag(flag): with pytest.raises(ValueError): bitmask.extend_bit_flag_map('DetectorMap', DEAD=flag) with pytest.raises(ValueError): class DetectorMap(bitmask.BitFlagNameMap): DEAD=flag
def test_interpret_valid_mnemonic_bit_flags(flag, expected): flagmap = bitmask.extend_bit_flag_map('DetectorMap', CR=1, HOT=2) assert( bitmask.interpret_bit_flags(bit_flags=flag, flag_name_map=flagmap) == expected )
def test_map_delete_flag(): DetectorMap = bitmask.extend_bit_flag_map('DetectorMap', DEAD=1) with pytest.raises(AttributeError): del DetectorMap.DEAD1 with pytest.raises(AttributeError): del DetectorMap['DEAD1']
def test_map_access_undefined_flag(): DetectorMap = bitmask.extend_bit_flag_map('DetectorMap', DEAD=1) with pytest.raises(AttributeError): DetectorMap.DEAD1 with pytest.raises(AttributeError): DetectorMap['DEAD1']
def test_extend_map_redefine_flag(monkeypatch, caching): monkeypatch.setattr(bitmask, '_ENABLE_BITFLAG_CACHING', caching) class ObservatoryDQMap(bitmask.BitFlagNameMap): CR = 1 HOT = 2 DEAD = 4 with pytest.raises(AttributeError): bitmask.extend_bit_flag_map('DetectorMap', ObservatoryDQMap, __version__='1.0', DEAD=32) with pytest.raises(AttributeError): bitmask.extend_bit_flag_map('DetectorMap', ObservatoryDQMap, __version__='1.0', DEAD=32, dead=64)
def test_map_add_flags(): map1 = bitmask.extend_bit_flag_map('DetectorMap', CR=1) map2 = map1 + {'HOT': 2, 'DEAD': 4} assert map2.CR == 1 assert map2.HOT == 2 map2 = map1 + [('HOT', 2), ('DEAD', 4)] assert map2.CR == 1 assert map2.HOT == 2 map2 = map1 + ('HOT', 2) assert map2.CR == 1 assert map2.HOT == 2
def test_map_add_flags(): map1 = bitmask.extend_bit_flag_map('DetectorMap', CR=1) map2 = map1 + {'HOT': 2, 'DEAD': (4, 'a really dead pixel')} assert map2.CR == 1 assert map2.HOT == 2 assert map2.DEAD.__doc__ == 'a really dead pixel' assert map2.DEAD == 4 map2 = map1 + [('HOT', 2), ('DEAD', 4)] assert map2.CR == 1 assert map2.HOT == 2 map2 = map1 + ('HOT', 2) assert map2.CR == 1 assert map2.HOT == 2
def test_extend_map(monkeypatch, caching): monkeypatch.setattr(bitmask, '_ENABLE_BITFLAG_CACHING', caching) class ObservatoryDQMap(bitmask.BitFlagNameMap): CR = 1 HOT = 2 DEAD = 4 DetectorMap = bitmask.extend_bit_flag_map('DetectorMap', ObservatoryDQMap, __version__='1.0', DEAD=4, READOUT_ERR=16) assert DetectorMap.CR == 1 assert DetectorMap.readout_err == 16
def test_map_repr(): DetectorMap = bitmask.extend_bit_flag_map('DetectorMap', DEAD=1) assert repr(DetectorMap) == "<BitFlagNameMap 'DetectorMap'>"
def test_map_not_bit_flag(flag): with pytest.raises(ValueError): bitmask.extend_bit_flag_map('DetectorMap', DEAD=flag)