Skip to content

Commit 00d1c15

Browse files
committed
restructure test_main.py structure to allow setup and teardown of testing suite
1 parent bcbdb24 commit 00d1c15

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/test_CodeEntropy/test_main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import os
2+
import shutil
3+
import tempfile
14
import unittest
25
from unittest.mock import MagicMock, patch
36

@@ -9,6 +12,22 @@ class TestMain(unittest.TestCase):
912
Unit tests for the main functionality of CodeEntropy.
1013
"""
1114

15+
def setUp(self):
16+
"""
17+
Set up a temporary directory as the working directory before each test.
18+
"""
19+
self.test_dir = tempfile.mkdtemp(prefix="CodeEntropy_")
20+
self._orig_dir = os.getcwd()
21+
os.chdir(self.test_dir)
22+
23+
def tearDown(self):
24+
"""
25+
Clean up by removing the temporary directory and restoring the original working
26+
directory.
27+
"""
28+
os.chdir(self._orig_dir)
29+
shutil.rmtree(self.test_dir)
30+
1231
@patch("CodeEntropy.main.sys.exit")
1332
@patch("CodeEntropy.main.RunManager")
1433
def test_main_successful_run(self, mock_RunManager, mock_exit):

0 commit comments

Comments
 (0)