11"""Tests for notebook structure validation."""
2+
23import json
34
45import nbformat
@@ -16,9 +17,9 @@ def test_no_execution_counts(self, notebook_files):
1617
1718 for cell in nb .get ("cells" , []):
1819 execution_count = cell .get ("execution_count" )
19- assert (
20- execution_count is None
21- ), f"Notebook { notebook_path } has execution_count { execution_count } in cell"
20+ assert execution_count is None , (
21+ f"Notebook { notebook_path } has execution_count { execution_count } in cell"
22+ )
2223
2324 def test_no_stored_outputs (self , notebook_files ):
2425 """Test that notebooks have no stored outputs."""
@@ -28,9 +29,9 @@ def test_no_stored_outputs(self, notebook_files):
2829
2930 for i , cell in enumerate (nb .get ("cells" , [])):
3031 outputs = cell .get ("outputs" , [])
31- assert (
32- len (outputs ) == 0
33- ), f"Notebook { notebook_path } has { len ( outputs ) } outputs in cell { i } "
32+ assert len ( outputs ) == 0 , (
33+ f"Notebook { notebook_path } has { len (outputs )} outputs in cell { i } "
34+ )
3435
3536 def test_kernelspec_consistency (self , notebook_files ):
3637 """Test that all notebooks have consistent kernelspec.name."""
@@ -51,9 +52,9 @@ def test_kernelspec_consistency(self, notebook_files):
5152 # Get the first kernelspec name as the reference
5253 first_name = kernelspecs [0 ][1 ]
5354 for notebook_path , name in kernelspecs :
54- assert (
55- name == first_name
56- ), f"Notebook { notebook_path } has kernelspec.name ' { name } ', expected ' { first_name } '"
55+ assert name == first_name , (
56+ f"Notebook { notebook_path } has kernelspec. name ' { name } ', expected ' { first_name } '"
57+ )
5758
5859 def test_language_info_version_consistency (self , notebook_files ):
5960 """Test that all notebooks have consistent language_info.version."""
@@ -74,9 +75,9 @@ def test_language_info_version_consistency(self, notebook_files):
7475 # Get the first version as the reference
7576 first_version = versions [0 ][1 ]
7677 for notebook_path , version in versions :
77- assert (
78- version == first_version
79- ), f"Notebook { notebook_path } has language_info.version ' { version } ', expected ' { first_version } '"
78+ assert version == first_version , (
79+ f"Notebook { notebook_path } has language_info. version ' { version } ', expected ' { first_version } '"
80+ )
8081
8182 def test_no_environment_specific_metadata (self , notebook_files ):
8283 """Test that notebooks don't contain environment-specific metadata."""
@@ -130,9 +131,9 @@ def test_standardized_metadata_schema(self, notebook_files):
130131 first_core = first_metadata_keys & core_keys
131132 current_core = metadata_keys & core_keys
132133
133- assert (
134- first_core == current_core
135- ), f"Notebook { notebook_path } has different core metadata keys. Expected { first_core } , got { current_core } "
134+ assert first_core == current_core , (
135+ f"Notebook { notebook_path } has different core metadata keys. Expected { first_core } , got { current_core } "
136+ )
136137
137138 def test_required_sections_exist (self , notebook_files ):
138139 """Test that notebooks contain required sections."""
@@ -163,9 +164,9 @@ def test_required_sections_exist(self, notebook_files):
163164 keyword for keyword in required_keywords if keyword in content_lower
164165 ]
165166 # At minimum, should have import or install/setup
166- assert (
167- len ( found_keywords ) > 0
168- ), f"Notebook { notebook_path } missing required sections (imports, setup, or install)"
167+ assert len ( found_keywords ) > 0 , (
168+ f"Notebook { notebook_path } missing required sections (imports, setup, or install)"
169+ )
169170
170171 def test_cell_type_ordering (self , notebook_files ):
171172 """Test that notebooks have logical ordering of markdown and code cells."""
@@ -182,7 +183,9 @@ def test_cell_type_ordering(self, notebook_files):
182183 assert first_cell_type in [
183184 "markdown" ,
184185 "code" ,
185- ], f"Notebook { notebook_path } first cell has unexpected type: { first_cell_type } "
186+ ], (
187+ f"Notebook { notebook_path } first cell has unexpected type: { first_cell_type } "
188+ )
186189
187190 def test_no_empty_cells (self , notebook_files ):
188191 """Test that notebooks have no empty cells."""
@@ -210,17 +213,12 @@ def test_notebooks_are_valid_json(self, notebook_files):
210213 with open (notebook_path , encoding = "utf-8" ) as f :
211214 json .load (f )
212215 except json .JSONDecodeError as e :
213- pytest .fail (
214- f"Notebook { notebook_path } is not valid JSON: { e } "
215- )
216+ pytest .fail (f"Notebook { notebook_path } is not valid JSON: { e } " )
216217
217218 def test_notebooks_are_valid_nbformat (self , notebook_files ):
218219 """Test that all notebook files are valid nbformat."""
219220 for notebook_path in notebook_files :
220221 try :
221222 nbformat .read (str (notebook_path ), as_version = 4 )
222223 except Exception as e :
223- pytest .fail (
224- f"Notebook { notebook_path } is not valid nbformat: { e } "
225- )
226-
224+ pytest .fail (f"Notebook { notebook_path } is not valid nbformat: { e } " )
0 commit comments