def test_property_path_coercion(): prop = Property(Path) prop.set('hello/world.c') assert prop.get() == Path('hello/world.c') prop = ListProperty(Path) prop.set({'hello/world.c'}) assert prop.get() == [Path('hello/world.c')]
def test_property_enum_coercion(): class MyEnum(enum.Enum): ABC = enum.auto() prop = Property(MyEnum) prop.set('abc') assert prop.get() == MyEnum.ABC prop = ListProperty(MyEnum) prop.set(['abc']) assert prop.get() == [MyEnum.ABC]
def test_property_operators(): # Test concatenation if the property value is populated. prop1 = ListProperty(str, name='prop1') prop1.set(['hello']) assert (prop1 + ['world']).get() == ['hello', 'world'] prop1 = Property(str, name='prop1') prop1.set('hello') assert (prop1 + ' world').get() == 'hello world' # Concatenating an un-set property will fall back to an empty default. prop1 = ListProperty(str, name='prop1') assert (prop1 + ['value']).get() == ['value'] prop1 = Property(str, name='prop1') assert (prop1 + 'value').get() == 'value'
def unwrap_file_property(prop: Property) -> t.Tuple[bool, bool, t.List[Path]]: is_sequence, is_input_file_property, is_output_file_property = check_file_property( prop) if not is_input_file_property and not is_output_file_property: return [] value = prop.or_else(None) if value is None: result = [] else: result = list(value if is_sequence else [value]) return result
def test_property_nesting_1(): prop1 = ListProperty(str, name='prop1') prop2 = Property(str, name='prop2') prop1.set(['hello', prop2]) prop2.set('world') assert prop1.get() == ['hello', 'world']
class MyClass(HavingProperties): a = Property(int, default=42) b = Property(str)
class MyClass(HavingProperties): a = Property(int) b = ListProperty(str)