def test_is_set(self): record = AttrRecord('test', 'ON_INIT') self.assertTrue(record.is_set) record = AttrRecord('test', 'ON_SET') self.assertTrue(record.is_set) record = AttrRecord('test', 'NOT_SET') self.assertFalse(record.is_set)
def test_attr_records_dict(self): inst = Test('A', 1) records = attr_records_dict(inst) self.assertEqual(records, { 'first': AttrRecord(name='first', set_on='ON_INIT'), 'second': AttrRecord(name='second', set_on='ON_INIT'), 'third': AttrRecord(name='third', set_on='NOT_SET') })
def test_record_init_kwargs_as_args(self): inst = Test('A', 1, True) records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_INIT'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='ON_INIT') ) )
def test_record_pydantic_dataclass(self): inst = PydanticDataclass('A', 1) records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_INIT'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='NOT_SET') ) )
def test_record_on_init_value_set_to_default_still_recorded(self): # False is the default for "third" but we've explicitly set this value, so it is recorded as set_on=ON_INIT inst = Test('A', 1, third=False) records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_INIT'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='ON_INIT') ) )
def test_record_on_set(self): inst = Test('A', 1) inst.first = 'B' inst.third = True records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_SET'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='ON_SET') ) )
def test_pydantic_from_dict(self): inst = parse_obj_as(PydanticDataclass, {'first': 'A', 'second': 1}) records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_INIT'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='NOT_SET') ) ) inst = parse_obj_as(PydanticDataclass, {'first': 'A', 'second': 1, 'third': True}) records = attr_records(inst) self.assertEqual(records, ( AttrRecord(name='first', set_on='ON_INIT'), AttrRecord(name='second', set_on='ON_INIT'), AttrRecord(name='third', set_on='ON_INIT') ) )