Skip to content

Commit

Permalink
Automated add-commit-push. Datetime tag: 18/12/2023 21:48:45
Browse files Browse the repository at this point in the history
  • Loading branch information
pakkinlau committed Dec 18, 2023
1 parent 2b0f3a0 commit 62718bd
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 6 deletions.
Binary file added gites/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 5 additions & 6 deletions gites/subpackage/pull_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ def lpull(self):
self.failed_repo.append(repo)
print("Git status command failed.")
continue # type: ignore
# Case 2: 'Updating' - indicates that there is new updates in the remote server.
if "Updating" in stdout:
self.success_repo.append(repo)
print("This repo has detected diff and has already pulled. Proceed the next repo.")
continue # type: ignore
# Case 2: 'Your branch is up to date'
if "Already up-to-date" in stdout:
self.no_effect_repo.append(repo)
print("This repo has no diff detected. Proceed the next repo.")
continue # type: ignore

# Case 3: 'changed' - indicates that there is new updates in the remote server.
if "changed" in stdout:
self.success_repo.append(repo)
print("This repo has detected diff and has already pulled. Proceed the next repo.")
continue # type: ignore
print("=" * 72)


Expand Down
Empty file added gites/tests/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions gites/tests/test_datastore_json_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Test module:
How to run it?
- Click "run" would fails.
When you run a Python script directly, Python doesn't set up the package context that's necessary for relative imports to work.
- To run your test, you should use `-m` flag with unittest.
This approach keep the folder structure intact
"""


import unittest
from unittest.mock import MagicMock, patch
from ..subpackage.datastore_json_handler import DatastoreJSONHandler

class TestConfigJSONHandler:
# Mock of the ConfigJSONHandler class
gites_datastore_json_location = "/mock/datastore.json"

class TestDatastoreJSONHandler(unittest.TestCase):
def setUp(self):
# Patch the ConfigJSONHandler to return a mock instance
patcher = patch('datastore_json_handler.ConfigJSONHandler', new=TestConfigJSONHandler)
self.mock_config = patcher.start()
self.addCleanup(patcher.stop)

# Mock data to be used in tests
self.mock_datastore_data = {
"repositories": [
{"name": "repo1", "remote_url": "https://example.com/repo1.git"},
{"name": "repo2", "remote_url": "https://example.com/repo2.git"}
],
"root_directories": {
"linux": "/linux/root",
"windows": "C:\\windows\\root"
}
}

def test_load_datastore_json(self):
# Mock os.path.exists to always return True
with patch('os.path.exists', return_value=True):
# Mock the builtin open function to mock the file reading
with patch('builtins.open', unittest.mock.mock_open(read_data=json.dumps(self.mock_datastore_data))):
handler = DatastoreJSONHandler()
# Assert that the data is loaded correctly
self.assertEqual(handler.data, self.mock_datastore_data)

def test_get_root_directory_linux(self):
# Set the os.name to 'posix' to simulate a Linux environment
with patch('os.name', 'posix'):
handler = DatastoreJSONHandler()
# Assert that the Linux root directory is returned
self.assertEqual(handler.get_root_directory(), "/linux/root")

def test_get_root_directory_windows(self):
# Set the os.name to 'nt' to simulate a Windows environment
with patch('os.name', 'nt'):
handler = DatastoreJSONHandler()
# Assert that the Windows root directory is returned
self.assertEqual(handler.get_root_directory(), "C:\\windows\\root")

# Add more tests here to cover different scenarios and edge cases

if __name__ == '__main__':
unittest.main()

0 comments on commit 62718bd

Please sign in to comment.