def test_replace(self): for spec in self.instances: for field_name, field_spec in spec.get_fields(): spec_dict = spec.to_dict(include_all=True) if isinstance(field_spec, PrimitiveField): spec_dict[field_name] = replace_val = 1 else: self.assertRaises(InvalidSpecInstance, spec.replace, **{field_name: 1}) if isinstance(field_spec, BaseSpecField): replace_val = [ e for e in self.instances if field_spec.check_valid_value(e) ][0] spec_dict[field_name] = replace_val.to_dict( include_all=True) else: replace_val = [Spec()] spec_dict[field_name] = [ replace_val[0].to_dict(include_all=True) ] replaced_spec_dict = spec.replace(**{ field_name: replace_val }).to_dict(include_all=True) assert replaced_spec_dict == spec_dict
def test_create_refactor(self): specs = get_test_specs(easy=True) + get_test_data_stores() specs = [ e for e in specs if not isinstance(e, SpecB) and not isinstance(e, SpecWithDefault) ] specs.append(func(Spec())) specs.append(func(A())) specs.append(func(A(H(0)))) specs.append(func(A(H(1)))) for s1 in specs: for s2 in specs: s1_dict = s1.to_dict() s2_dict = s2.to_dict() diff = Diff.build(s1_dict, s2_dict) r = diff.create_refactor() refactored_dict = r.bind(s1_dict).execute() assert refactored_dict == s2_dict