From 418f82bb9715e13a1203008d4518e389c15f27b5 Mon Sep 17 00:00:00 2001 From: "martin.cholewa" Date: Mon, 31 Mar 2025 13:37:44 +0200 Subject: [PATCH] test for python code --- test_mobius_repos.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test_mobius_repos.py diff --git a/test_mobius_repos.py b/test_mobius_repos.py new file mode 100644 index 0000000..9a4989e --- /dev/null +++ b/test_mobius_repos.py @@ -0,0 +1,59 @@ +import os +import pytest +import subprocess +from pathlib import Path +from mobius_repos import create_new_branch, git_checkout_and_pull, load_repositories +from helpers import Colors, print_colored + +@pytest.fixture(scope="module") +def repo_paths(): + """Load repository paths from repos.txt""" + repos = load_repositories("repos.txt") + if not repos: + pytest.skip("File repos.txt is not available or is empty") + return repos + +def test_load_repositories(): + """Test loading repositories from repos.txt""" + repos = load_repositories("repos.txt") + assert isinstance(repos, list), "Loaded repositories should be in a list" + assert len(repos) > 0, "repos.txt should not be empty" + + # Test that all paths in the file exist + for repo_path in repos: + assert os.path.exists(repo_path), f"Path {repo_path} does not exist" + assert os.path.exists(os.path.join(repo_path, '.git')), f"Path {repo_path} is not a git repository" + +def test_git_checkout_and_pull(repo_paths): + """Test switching to develop branch and pull""" + original_dir = os.getcwd() + + for repo_path in repo_paths: + try: + # Test checkout and pull + result = git_checkout_and_pull(repo_path) + assert result == True, f"Checkout and pull failed for {repo_path}" + + # Verify we are on develop branch + os.chdir(repo_path) + current_branch = subprocess.check_output(['git', 'branch', '--show-current']).decode().strip() + assert current_branch == 'develop', f"Repository {repo_path} is not on develop branch" + + finally: + os.chdir(original_dir) + +def test_invalid_repository(): + """Test operations with invalid repository""" + invalid_path = "/nonexistent/path/to/repo" + + # Test checkout and pull + result = git_checkout_and_pull(invalid_path) + assert result == False, "Operation should fail for non-existent repository" + + # Test branch creation + result = create_new_branch(invalid_path, "test-branch") + assert result == False, "Operation should fail for non-existent repository" + +if __name__ == '__main__': + pytest.main(['-v']) +