Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 6, 2025
1 parent ed84d10 commit d4486e1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tests/unit/spec_tests/test_spec_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def setUp(self):
doc='Extensions for my lab',
title='My lab extensions')
self.ns_builder.export(self.namespace_path)

# Additional paths for export tests
self.output_path = "test_export.namespace.yaml"
self.source_path = "test_source.yaml"

# Create a test spec for reuse
self.test_spec = GroupSpec('A test group',
data_type_def='TestGroup',
Expand All @@ -112,7 +112,7 @@ def tearDown(self):
os.remove(self.ext_source_path)
if os.path.exists(self.namespace_path):
os.remove(self.namespace_path)

# Additional cleanup for export tests
if os.path.exists(self.output_path):
os.remove(self.output_path)
Expand All @@ -128,9 +128,9 @@ def test_export_with_included_types(self):
"""Test export with included types from source."""
self.ns_builder.include_type('TestType1', source=self.source_path)
self.ns_builder.include_type('TestType2', source=self.source_path)

self.ns_builder.export(self.output_path)

# Verify the exported namespace
with open(self.output_path, 'r') as f:
content = f.read()
Expand All @@ -145,9 +145,9 @@ def test_export_with_included_namespaces(self):
namespace = "test_namespace"
self.ns_builder.include_namespace(namespace)
self.ns_builder.include_type('TestType1', namespace=namespace)

self.ns_builder.export(self.output_path)

# Verify the exported namespace
with open(self.output_path, 'r') as f:
content = f.read()
Expand All @@ -158,7 +158,7 @@ def test_export_source_with_specs(self):
"""Test export with source containing specs."""
self.ns_builder.add_spec(self.source_path, self.test_spec)
self.ns_builder.export(self.output_path)

# Verify the spec was written to source file
self.assertTrue(os.path.exists(self.source_path))
with open(self.source_path, 'r') as f:
Expand All @@ -171,7 +171,7 @@ def test_export_source_conflict_error(self):
# Add both an included type and a spec to the same source
self.ns_builder.include_type('TestType', source=self.source_path)
self.ns_builder.add_spec(self.source_path, self.test_spec)

# Verify export raises error
with self.assertRaises(ValueError):
self.ns_builder.export(self.output_path)
Expand All @@ -182,9 +182,9 @@ def test_export_source_with_doc_title(self):
doc='Test documentation',
title='Test Title')
self.ns_builder.add_spec(self.source_path, self.test_spec)

self.ns_builder.export(self.output_path)

# Verify doc and title in namespace file
with open(self.output_path, 'r') as f:
content = f.read()
Expand Down Expand Up @@ -274,7 +274,7 @@ def setUp(self):
self.ns_builder.add_source(source=self.ext_source_path,
doc='Extensions for my lab',
title='My lab extensions')

# Create a temporary YAML file for reorder_yaml testing
self.temp_yaml = 'temp_test.yaml'
with open(self.temp_yaml, 'w') as f:
Expand Down Expand Up @@ -319,22 +319,22 @@ def test_get_name(self):
def test_reorder_yaml(self):
"""Test that reorder_yaml correctly loads, reorders, and saves a YAML file."""
writer = YAMLSpecWriter()

# Reorder the YAML file
writer.reorder_yaml(self.temp_yaml)

# Read the reordered content
with open(self.temp_yaml, 'r') as f:
content = f.read()

# Verify the order of keys in the reordered content
# The name should come before dtype and doc
name_pos = content.find('name: test name')
dtype_pos = content.find('dtype: int')
doc_pos = content.find('doc: test doc')
self.assertLess(name_pos, dtype_pos)
self.assertLess(dtype_pos, doc_pos)

# Verify nested structures are also reordered
attr_block = content[content.find('- name: attr1'):content.find('groups:')]
self.assertLess(attr_block.find('name: attr1'), attr_block.find('dtype: float'))
Expand All @@ -343,7 +343,7 @@ def test_reorder_yaml(self):
def test_sort_keys(self):
"""Test that sort_keys correctly orders dictionary keys according to the predefined order."""
writer = YAMLSpecWriter()

# Test basic ordering with predefined keys
input_dict = {
'doc': 'documentation',
Expand All @@ -354,11 +354,11 @@ def test_sort_keys(self):
'groups': [3]
}
result = writer.sort_keys(input_dict)

# Check that the keys are in the correct order
expected_order = ['name', 'dtype', 'doc', 'attributes', 'datasets', 'groups']
self.assertEqual(list(result.keys()), expected_order)

# Test neurodata_type_def positioning
input_dict = {
'doc': 'documentation',
Expand All @@ -368,7 +368,7 @@ def test_sort_keys(self):
}
result = writer.sort_keys(input_dict)
self.assertEqual(list(result.keys())[0], 'neurodata_type_def')

# Test nested dictionary ordering
input_dict = {
'doc': 'documentation',
Expand All @@ -381,7 +381,7 @@ def test_sort_keys(self):
}
result = writer.sort_keys(input_dict)
self.assertEqual(list(result['nested'].keys()), ['name', 'dtype', 'attributes', 'groups'])

# Test list handling
input_dict = {
'attributes': [
Expand Down

0 comments on commit d4486e1

Please sign in to comment.