@@ -35,13 +35,25 @@ def test_getting_started_example_imports(self):
3535 # Test that the file can be imported without syntax errors
3636 try :
3737 import importlib .util
38- spec = importlib .util .spec_from_file_location ("getting_started" , example_file )
39- module = importlib .util .module_from_spec (spec )
40- spec .loader .exec_module (module )
41-
42- # Check that key components are defined
43- assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
44- assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
38+ from unittest .mock import patch
39+
40+ # Mock export_graph to write to temp directory instead of current directory
41+ def mock_export_graph (format , output = None , ** kwargs ):
42+ if output :
43+ # Create a temp file in our temp directory instead
44+ temp_output = Path (self .temp_dir ) / Path (output ).name
45+ temp_output .write_text (f"Mock { format } export content" )
46+ return str (temp_output )
47+ return f"mock_{ format } _export.{ format } "
48+
49+ with patch ('graphflow.core.pipeline.Pipeline.export_graph' , side_effect = mock_export_graph ):
50+ spec = importlib .util .spec_from_file_location ("getting_started" , example_file )
51+ module = importlib .util .module_from_spec (spec )
52+ spec .loader .exec_module (module )
53+
54+ # Check that key components are defined
55+ assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
56+ assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
4557
4658 except Exception as e :
4759 pytest .fail (f"Failed to import getting started example: { e } " )
@@ -56,13 +68,25 @@ def test_advanced_features_example_imports(self):
5668 # Test that the file can be imported without syntax errors
5769 try :
5870 import importlib .util
59- spec = importlib .util .spec_from_file_location ("advanced_features" , example_file )
60- module = importlib .util .module_from_spec (spec )
61- spec .loader .exec_module (module )
62-
63- # Check that key components are defined
64- assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
65- assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
71+ from unittest .mock import patch
72+
73+ # Mock export_graph to write to temp directory instead of current directory
74+ def mock_export_graph (format , output = None , ** kwargs ):
75+ if output :
76+ # Create a temp file in our temp directory instead
77+ temp_output = Path (self .temp_dir ) / Path (output ).name
78+ temp_output .write_text (f"Mock { format } export content" )
79+ return str (temp_output )
80+ return f"mock_{ format } _export.{ format } "
81+
82+ with patch ('graphflow.core.pipeline.Pipeline.export_graph' , side_effect = mock_export_graph ):
83+ spec = importlib .util .spec_from_file_location ("advanced_features" , example_file )
84+ module = importlib .util .module_from_spec (spec )
85+ spec .loader .exec_module (module )
86+
87+ # Check that key components are defined
88+ assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
89+ assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
6690
6791 except Exception as e :
6892 pytest .fail (f"Failed to import advanced features example: { e } " )
@@ -77,13 +101,25 @@ def test_data_validation_example_imports(self):
77101 # Test that the file can be imported without syntax errors
78102 try :
79103 import importlib .util
80- spec = importlib .util .spec_from_file_location ("data_validation" , example_file )
81- module = importlib .util .module_from_spec (spec )
82- spec .loader .exec_module (module )
83-
84- # Check that key components are defined
85- assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
86- assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
104+ from unittest .mock import patch
105+
106+ # Mock export_graph to write to temp directory instead of current directory
107+ def mock_export_graph (format , output = None , ** kwargs ):
108+ if output :
109+ # Create a temp file in our temp directory instead
110+ temp_output = Path (self .temp_dir ) / Path (output ).name
111+ temp_output .write_text (f"Mock { format } export content" )
112+ return str (temp_output )
113+ return f"mock_{ format } _export.{ format } "
114+
115+ with patch ('graphflow.core.pipeline.Pipeline.export_graph' , side_effect = mock_export_graph ):
116+ spec = importlib .util .spec_from_file_location ("data_validation" , example_file )
117+ module = importlib .util .module_from_spec (spec )
118+ spec .loader .exec_module (module )
119+
120+ # Check that key components are defined
121+ assert hasattr (module , 'ctx' ) or 'context(' in example_file .read_text ()
122+ assert hasattr (module , 'pipeline' ) or 'Pipeline(' in example_file .read_text ()
87123
88124 except Exception as e :
89125 pytest .fail (f"Failed to import data validation example: { e } " )
0 commit comments