branchGit/test_mobius_repos.py

60 lines
2.1 KiB
Python

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'])