Skip to content

Commit 2c64f5f

Browse files
committed
Update test_basic.py
1 parent 4e66a2b commit 2c64f5f

File tree

1 file changed

+118
-2
lines changed

1 file changed

+118
-2
lines changed

tests/test_basic.py

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
1-
def test_placeholder():
2-
assert True
1+
"""
2+
Basic tests for ModelSync
3+
"""
4+
5+
import pytest
6+
import tempfile
7+
import os
8+
from pathlib import Path
9+
from modelsync.core.versioning import ModelSyncRepo
10+
11+
class TestModelSyncRepo:
12+
"""Test cases for ModelSyncRepo"""
13+
14+
def setup_method(self):
15+
"""Setup test environment"""
16+
self.temp_dir = tempfile.mkdtemp()
17+
self.repo = ModelSyncRepo(self.temp_dir)
18+
19+
def teardown_method(self):
20+
"""Cleanup test environment"""
21+
import shutil
22+
shutil.rmtree(self.temp_dir)
23+
24+
def test_init_repository(self):
25+
"""Test repository initialization"""
26+
# Should not be initialized initially
27+
assert not self.repo.is_initialized()
28+
29+
# Initialize repository
30+
result = self.repo.init("Test User", "test@example.com")
31+
assert result is True
32+
assert self.repo.is_initialized()
33+
34+
# Check if directories were created
35+
assert (Path(self.temp_dir) / ".modelsync").exists()
36+
assert (Path(self.temp_dir) / ".modelsync" / "objects").exists()
37+
assert (Path(self.temp_dir) / ".modelsync" / "refs").exists()
38+
assert (Path(self.temp_dir) / ".modelsync" / "refs" / "heads").exists()
39+
40+
def test_add_files(self):
41+
"""Test adding files to staging area"""
42+
# Initialize repository first
43+
self.repo.init("Test User", "test@example.com")
44+
45+
# Create test files
46+
test_file1 = Path(self.temp_dir) / "test1.py"
47+
test_file2 = Path(self.temp_dir) / "test2.json"
48+
49+
test_file1.write_text("print('hello world')")
50+
test_file2.write_text('{"test": "data"}')
51+
52+
# Add files
53+
added_files = self.repo.add(["test1.py", "test2.json"])
54+
55+
assert len(added_files) == 2
56+
assert "test1.py" in added_files
57+
assert "test2.json" in added_files
58+
59+
def test_commit(self):
60+
"""Test creating commits"""
61+
# Initialize repository
62+
self.repo.init("Test User", "test@example.com")
63+
64+
# Create and add test file
65+
test_file = Path(self.temp_dir) / "test.py"
66+
test_file.write_text("print('hello world')")
67+
68+
self.repo.add(["test.py"])
69+
70+
# Create commit
71+
commit_hash = self.repo.commit("Test commit")
72+
73+
assert commit_hash is not None
74+
assert len(commit_hash) == 64 # SHA-256 hash length
75+
76+
def test_status(self):
77+
"""Test repository status"""
78+
# Initialize repository
79+
self.repo.init("Test User", "test@example.com")
80+
81+
# Create test file
82+
test_file = Path(self.temp_dir) / "test.py"
83+
test_file.write_text("print('hello world')")
84+
85+
# Check status before adding
86+
status = self.repo.status()
87+
assert status["total_tracked"] >= 1
88+
assert status["total_staged"] == 0
89+
90+
# Add file and check status
91+
self.repo.add(["test.py"])
92+
status = self.repo.status()
93+
assert status["total_staged"] == 1
94+
assert "test.py" in status["staged_files"]
95+
96+
def test_log(self):
97+
"""Test commit log"""
98+
# Initialize repository
99+
self.repo.init("Test User", "test@example.com")
100+
101+
# Create and commit test file
102+
test_file = Path(self.temp_dir) / "test.py"
103+
test_file.write_text("print('hello world')")
104+
105+
self.repo.add(["test.py"])
106+
commit_hash = self.repo.commit("Test commit")
107+
108+
# Check log
109+
commits = self.repo.log()
110+
assert len(commits) >= 1 # At least initial commit + our commit
111+
112+
# Find our commit
113+
our_commit = next((c for c in commits if c["message"] == "Test commit"), None)
114+
assert our_commit is not None
115+
assert our_commit["hash"] == commit_hash
116+
117+
if __name__ == "__main__":
118+
pytest.main([__file__])

0 commit comments

Comments
 (0)