-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use same cache directory #466
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- tests/test_cache_executor_pysqa_flux.py (1 hunks)
🔇 Additional comments (1)
tests/test_cache_executor_pysqa_flux.py (1)
37-37
: LGTM! Good alignment of cache and working directories.
The changes consistently use the same directory for both cache storage and working directory, which is a good practice for test organization and cleanup.
Also applies to: 39-39
@@ -34,8 +34,9 @@ class TestCacheExecutorPysqa(unittest.TestCase): | |||
def test_executor(self): | |||
with Executor( | |||
backend="pysqa_flux", | |||
resource_dict={"cores": 2, "cwd": "exe_working_directory"}, | |||
resource_dict={"cores": 2, "cwd": "cache"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
🛠️ Refactor suggestion
Consistent test isolation improvements needed across test files
The review suggestion is valid and should be applied consistently across the test suite. The investigation reveals that:
- All test files use hardcoded "cache" directory
- All files implement tearDown for cleanup, but none use tempfile for isolation
- No setUp methods are currently implemented in any of these files
- Similar cleanup pattern
if os.path.exists("cache"): shutil.rmtree("cache")
is repeated
Suggested improvements for all affected files:
- tests/test_cache_executor_pysqa_flux.py
- tests/test_executor_backend_mpi.py
- tests/test_cache_shared.py
- tests/test_cache_hdf.py
- tests/test_cache_executor_serial.py
🔗 Analysis chain
Consider improving path handling and test isolation.
While the current implementation works, consider these improvements:
- Use
tempfile.mkdtemp()
for test isolation - Use absolute paths to avoid potential working directory issues
Here's a suggested implementation:
+import tempfile
+
class TestCacheExecutorPysqa(unittest.TestCase):
+ def setUp(self):
+ self.test_dir = tempfile.mkdtemp(prefix="cache_executor_test_")
+
def test_executor(self):
with Executor(
backend="pysqa_flux",
- resource_dict={"cores": 2, "cwd": "cache"},
+ resource_dict={"cores": 2, "cwd": self.test_dir},
block_allocation=False,
- cache_directory="cache",
+ cache_directory=self.test_dir,
) as exe:
def tearDown(self):
- if os.path.exists("cache"):
- shutil.rmtree("cache")
+ if os.path.exists(self.test_dir):
+ shutil.rmtree(self.test_dir)
Let's check if other test files use similar cache directory patterns:
Also applies to: 39-39
Let's examine the cache directory usage in the other test files to understand the pattern and verify if the suggested improvements should be applied consistently.
Let's check if these test files already have cleanup mechanisms in place and if they use any temporary directory solutions.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for cache directory patterns in test files
echo "Searching for cache directory patterns in tests:"
rg -l "cache_directory|cwd.*cache" tests/
Length of output: 312
Script:
#!/bin/bash
# Check cache directory usage in the identified test files
echo "=== test_executor_backend_mpi.py ==="
rg "cache_directory|cwd.*cache" tests/test_executor_backend_mpi.py -B 2 -A 2
echo -e "\n=== test_cache_shared.py ==="
rg "cache_directory|cwd.*cache" tests/test_cache_shared.py -B 2 -A 2
echo -e "\n=== test_cache_hdf.py ==="
rg "cache_directory|cwd.*cache" tests/test_cache_hdf.py -B 2 -A 2
echo -e "\n=== test_cache_executor_serial.py ==="
rg "cache_directory|cwd.*cache" tests/test_cache_executor_serial.py -B 2 -A 2
Length of output: 4827
Script:
#!/bin/bash
# Check for cleanup and temporary directory usage
echo "=== Checking for tearDown and temporary directory usage ==="
for file in tests/test_executor_backend_mpi.py tests/test_cache_shared.py tests/test_cache_hdf.py tests/test_cache_executor_serial.py; do
echo -e "\n=== $file ==="
# Look for tearDown methods and cleanup code
rg "def tearDown|rmtree|tempfile" "$file" -B 1 -A 3
# Look for setUp methods
echo -e "\n--- setUp methods in $file ---"
rg "def setUp" "$file" -B 1 -A 3
done
Length of output: 2585
Summary by CodeRabbit
Executor
to improve resource allocation and cache file management during test execution.