Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/test_cache_executor_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ def test_executor_function_dependence_args(self):
q.put({"shutdown": True, "wait": True})
process.join()

def test_execute_in_subprocess_errors(self):
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], config_directory="test")
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], backend="flux")

Comment on lines +170 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing test coverage with additional cases.

While the current test covers basic error handling, consider adding:

  1. A docstring explaining the test's purpose
  2. Validation of error message content
  3. Additional invalid command scenarios

Here's a suggested enhancement:

     def test_execute_in_subprocess_errors(self):
+        """Test that execute_in_subprocess properly handles invalid inputs."""
         with self.assertRaises(ValueError):
-            execute_in_subprocess(command=[], config_directory="test")
+            execute_in_subprocess(command=[], config_directory="test")
+            
+        with self.assertRaises(ValueError) as cm:
+            execute_in_subprocess(command=None)
+        self.assertIn("command cannot be empty", str(cm.exception))
+            
         with self.assertRaises(ValueError):
             execute_in_subprocess(command=[], backend="flux")
+            
+        with self.assertRaises(TypeError):
+            execute_in_subprocess(command="not_a_list")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_execute_in_subprocess_errors(self):
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], config_directory="test")
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], backend="flux")
def test_execute_in_subprocess_errors(self):
"""Test that execute_in_subprocess properly handles invalid inputs."""
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], config_directory="test")
with self.assertRaises(ValueError) as cm:
execute_in_subprocess(command=None)
self.assertIn("command cannot be empty", str(cm.exception))
with self.assertRaises(ValueError):
execute_in_subprocess(command=[], backend="flux")
with self.assertRaises(TypeError):
execute_in_subprocess(command="not_a_list")

def tearDown(self):
if os.path.exists("cache"):
shutil.rmtree("cache")
11 changes: 10 additions & 1 deletion tests/test_cache_hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


try:
from executorlib.standalone.hdf import dump, load
from executorlib.standalone.hdf import dump, load, get_output

skip_h5py_test = False
except ImportError:
Expand Down Expand Up @@ -33,6 +33,9 @@ def test_hdf_mixed(self):
self.assertTrue("fn" in data_dict.keys())
self.assertEqual(data_dict["args"], [a])
self.assertEqual(data_dict["kwargs"], {"b": b})
flag, output = get_output(file_name=file_name)
self.assertFalse(flag)
self.assertIsNone(output)

def test_hdf_args(self):
cache_directory = os.path.abspath("cache")
Expand All @@ -45,6 +48,9 @@ def test_hdf_args(self):
self.assertTrue("fn" in data_dict.keys())
self.assertEqual(data_dict["args"], [a, b])
self.assertEqual(data_dict["kwargs"], {})
flag, output = get_output(file_name=file_name)
self.assertFalse(flag)
self.assertIsNone(output)

def test_hdf_kwargs(self):
cache_directory = os.path.abspath("cache")
Expand All @@ -60,6 +66,9 @@ def test_hdf_kwargs(self):
self.assertTrue("fn" in data_dict.keys())
self.assertEqual(data_dict["args"], ())
self.assertEqual(data_dict["kwargs"], {"a": a, "b": b})
flag, output = get_output(file_name=file_name)
self.assertFalse(flag)
self.assertIsNone(output)

def tearDown(self):
if os.path.exists("cache"):
Expand Down
18 changes: 17 additions & 1 deletion tests/test_executor_backend_mpi_noblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,27 @@ def resource_dict(resource_dict):


class TestExecutorBackend(unittest.TestCase):
def test_meta_executor_serial(self):
def test_meta_executor_serial_with_dependencies(self):
with Executor(
max_cores=2,
backend="local",
block_allocation=False,
disable_dependencies=True,
) as exe:
cloudpickle_register(ind=1)
fs_1 = exe.submit(calc, 1)
fs_2 = exe.submit(calc, 2)
self.assertEqual(fs_1.result(), 1)
self.assertEqual(fs_2.result(), 2)
self.assertTrue(fs_1.done())
self.assertTrue(fs_2.done())

Comment on lines +16 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Method name contradicts the test configuration

The method name test_meta_executor_serial_with_dependencies suggests testing with dependencies enabled, but disable_dependencies=True does the opposite. Consider renaming to test_meta_executor_serial_disabled_dependencies for clarity.

-    def test_meta_executor_serial_with_dependencies(self):
+    def test_meta_executor_serial_disabled_dependencies(self):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_meta_executor_serial_with_dependencies(self):
with Executor(
max_cores=2,
backend="local",
block_allocation=False,
disable_dependencies=True,
) as exe:
cloudpickle_register(ind=1)
fs_1 = exe.submit(calc, 1)
fs_2 = exe.submit(calc, 2)
self.assertEqual(fs_1.result(), 1)
self.assertEqual(fs_2.result(), 2)
self.assertTrue(fs_1.done())
self.assertTrue(fs_2.done())
def test_meta_executor_serial_disabled_dependencies(self):
with Executor(
max_cores=2,
backend="local",
block_allocation=False,
disable_dependencies=True,
) as exe:
cloudpickle_register(ind=1)
fs_1 = exe.submit(calc, 1)
fs_2 = exe.submit(calc, 2)
self.assertEqual(fs_1.result(), 1)
self.assertEqual(fs_2.result(), 2)
self.assertTrue(fs_1.done())
self.assertTrue(fs_2.done())

def test_meta_executor_serial_without_dependencies(self):
with Executor(
max_cores=2,
backend="local",
block_allocation=False,
disable_dependencies=False,
) as exe:
cloudpickle_register(ind=1)
fs_1 = exe.submit(calc, 1)
Expand Down
Loading