def test_types(self, fixtures): base_file_path = py.path.local(fixtures['MultipleTypesDoc.asset']) doc = UnityDocument.load_yaml(str(base_file_path)) multi_types = doc.entry count_map = {'int': 0, 'str': 0, 'float': 0} def evaluate_type(attr, parent_map): attr_value = parent_map[attr] split_attr = attr.split('_') if split_attr[0] == 'scalar': expected_type = split_attr[1] assert type(attr_value).__name__ == expected_type count_map[expected_type] += 1 elif split_attr[0] == 'map': for k in attr_value: evaluate_type(k, attr_value) multi_types_attr_map = multi_types.get_serialized_properties_dict() for attribute in multi_types_attr_map: evaluate_type(attribute, multi_types_attr_map) assert count_map['int'] == 4 assert count_map['str'] == 8 assert count_map['float'] == 6
def test_sum_int_type(self, fixtures): base_file_path = py.path.local(fixtures['MultipleTypesDoc.asset']) doc = UnityDocument.load_yaml(str(base_file_path)) multi_types = doc.entry multi_types.scalar_int_001 += 1 assert multi_types.scalar_int_001 == 16
def test_single_doc_unchanged(self, fixtures, tmpdir): base_file_path = py.path.local(fixtures['SingleDoc.asset']) doc = UnityDocument.load_yaml(str(base_file_path)) dumped_file_path = tmpdir.join('SingleDoc.asset') doc.dump_yaml(file_path=str(dumped_file_path)) assert base_file_path.read() == dumped_file_path.read()
def test_unity_extra_anchor_data(self, fixtures, tmpdir): base_file_path = py.path.local(fixtures['UnityExtraAnchorData.prefab']) doc = UnityDocument.load_yaml(str(base_file_path)) dumped_file_path = tmpdir.join('UnityExtraAnchorData.prefab') doc.dump_yaml(file_path=str(dumped_file_path)) assert base_file_path.read() == dumped_file_path.read()
def test_get_entry(self, fixtures, class_name, attributes): multidoc_path = py.path.local(fixtures['MultiDoc.asset']) doc = UnityDocument.load_yaml(str(multidoc_path)) entry = doc.get(class_name=class_name, attributes=attributes) if class_name is not None: assert entry.__class__.__name__ == class_name if len(attributes): assert all(map(lambda attr: hasattr(entry, attr), attributes))
def test_filter_entries(self, fixtures, class_names, attributes, num_entries): multidoc_path = py.path.local(fixtures['MultiDoc.asset']) doc = UnityDocument.load_yaml(str(multidoc_path)) entries = doc.filter(class_names=class_names, attributes=attributes) assert len(entries) == num_entries if len(class_names): assert set([x.__class__.__name__ for x in entries]) <= set(class_names) if len(attributes): assert all( map( lambda x: all( map(lambda attr: hasattr(x, attr), attributes)), entries))