Skip to content
Merged
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
1 change: 1 addition & 0 deletions tests/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def execute_command(
slurm_tmp.get_queue_status(user="janj")
)
)
self.assertEqual(len(slurm_tmp.get_status_of_my_jobs()), 0)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Assertion is user-name dependent and can become flaky

get_status_of_my_jobs() filters by getpass.getuser() via _get_user().
The assertion that the result length is 0 only passes when the executing user is not "janj" or "maxi".
Running the suite on a machine where the current user matches one of those names will make the test fail even though the code works.

Tighten the test by mocking the username (or asserting the exact returned list) so the outcome is deterministic:

@@
-        self.assertEqual(len(slurm_tmp.get_status_of_my_jobs()), 0)
+        with unittest.mock.patch.object(slurm_tmp._adapter, "_get_user", return_value="nobody"):
+            self.assertListEqual(slurm_tmp.get_status_of_my_jobs(), [])

(You'll need import unittest.mock near the top of the file.)

This removes the environment dependency and specifies the expected value directly.


🏁 Script executed:

#!/bin/bash
set -e
echo "Searching for `get_status_of_my_jobs` references in tests:"
rg "get_status_of_my_jobs" -n tests/test_slurm.py || true

echo
echo "Searching for implementation of `get_status_of_my_jobs` in source:"
rg "def get_status_of_my_jobs" -n .

echo
echo "Searching for `_get_user` definition or usage in source:"
rg -n "_get_user" .

echo
echo "Searching for direct calls to `getpass.getuser`:"
rg -n "getpass.getuser" .

Length of output: 2478


Remove environment dependency in test_get_status_of_my_jobs

The test at tests/test_slurm.py:197 asserts that calling slurm_tmp.get_status_of_my_jobs() returns zero jobs using the real user from the environment. Since get_status_of_my_jobs() ultimately calls _get_user()getpass.getuser(), it will be non-zero when run as a user who actually has jobs queued.

Tighten this test by mocking the adapter’s _get_user() so it always returns a dummy user with no jobs:

• File: tests/test_slurm.py
Line: 197

-        self.assertEqual(len(slurm_tmp.get_status_of_my_jobs()), 0)
+        import unittest.mock  # add near the top of the file if not already present
+
+        # Force a user with no jobs for a deterministic result
+        with unittest.mock.patch.object(
+            slurm_tmp._adapter, "_get_user", return_value="nobody"
+        ):
+            self.assertListEqual(slurm_tmp.get_status_of_my_jobs(), [])

This removes any reliance on the runtime username and makes the expectation explicit.

📝 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
self.assertEqual(len(slurm_tmp.get_status_of_my_jobs()), 0)
import unittest.mock # add near the top of the file if not already present
# Force a user with no jobs for a deterministic result
with unittest.mock.patch.object(
slurm_tmp._adapter, "_get_user", return_value="nobody"
):
self.assertListEqual(slurm_tmp.get_status_of_my_jobs(), [])
🤖 Prompt for AI Agents
In tests/test_slurm.py at line 197, the test depends on the real environment
user which can cause inconsistent results. Fix this by mocking the slurm_tmp
adapter's _get_user() method to return a fixed dummy username before calling
get_status_of_my_jobs(). This ensures the test always runs with a controlled
user context and the job count expectation remains consistent.

self.assertEqual(slurm_tmp.get_status_of_job(process_id=5322019), "running")
self.assertIsNone(slurm_tmp.get_status_of_job(process_id=0))
self.assertEqual(
Expand Down
Loading