1- """Tests for configuration models."""
1+ """Tests for configuration models.
2+
3+ This module contains tests for the VCSPull configuration models.
4+ """
25
36from __future__ import annotations
47
5- from pathlib import Path
8+ import pathlib
69
710import pytest
811from pydantic import ValidationError
1114
1215
1316class TestRepository :
14- """Tests for the Repository model."""
17+ """Tests for Repository model."""
1518
1619 def test_minimal_repository (self ) -> None :
1720 """Test creating a repository with minimal fields."""
18- repo = Repository (url = "https://github.com/user/repo.git" , path = "~/code/repo" )
21+ repo = Repository (
22+ url = "https://github.com/user/repo.git" ,
23+ path = "~/code/repo" ,
24+ )
1925 assert repo .url == "https://github.com/user/repo.git"
20- assert str ( Path ( "~/code/repo" ). expanduser (). resolve ()) in repo . path
26+ assert repo . path . startswith ( "/" ) # Path should be normalized
2127 assert repo .vcs is None
2228 assert repo .name is None
23- assert repo .remotes == {}
29+ assert len ( repo .remotes ) == 0
2430 assert repo .rev is None
2531 assert repo .web_url is None
2632
2733 def test_full_repository (self ) -> None :
2834 """Test creating a repository with all fields."""
2935 repo = Repository (
30- name = "test-repo " ,
36+ name = "test" ,
3137 url = "https://github.com/user/repo.git" ,
3238 path = "~/code/repo" ,
3339 vcs = "git" ,
3440 remotes = {"upstream" : "https://github.com/upstream/repo.git" },
3541 rev = "main" ,
3642 web_url = "https://github.com/user/repo" ,
3743 )
38- assert repo .name == "test-repo "
44+ assert repo .name == "test"
3945 assert repo .url == "https://github.com/user/repo.git"
40- assert str ( Path ( "~/code/repo" ). expanduser (). resolve ()) in repo . path
46+ assert repo . path . startswith ( "/" ) # Path should be normalized
4147 assert repo .vcs == "git"
4248 assert repo .remotes == {"upstream" : "https://github.com/upstream/repo.git" }
4349 assert repo .rev == "main"
4450 assert repo .web_url == "https://github.com/user/repo"
4551
52+ def test_path_normalization (self , monkeypatch : pytest .MonkeyPatch ) -> None :
53+ """Test that paths are normalized."""
54+ # Mock the home directory for testing
55+ test_home = "/mock/home"
56+ monkeypatch .setenv ("HOME" , test_home )
57+
58+ repo = Repository (
59+ url = "https://github.com/user/repo.git" ,
60+ path = "~/code/repo" ,
61+ )
62+
63+ assert repo .path .startswith ("/" )
64+ assert "~" not in repo .path
65+ assert repo .path == str (pathlib .Path (test_home ) / "code/repo" )
66+
4667 def test_path_validation (self ) -> None :
4768 """Test path validation."""
4869 repo = Repository (url = "https://github.com/user/repo.git" , path = "~/code/repo" )
49- assert str (Path ("~/code/repo" ).expanduser ().resolve ()) in repo .path
70+ assert repo .path .startswith ("/" )
71+ assert "~" not in repo .path
5072
5173 def test_missing_required_fields (self ) -> None :
5274 """Test validation error when required fields are missing."""
@@ -66,17 +88,17 @@ def test_missing_required_fields(self) -> None:
6688
6789
6890class TestSettings :
69- """Tests for the Settings model."""
91+ """Tests for Settings model."""
7092
7193 def test_default_settings (self ) -> None :
72- """Test default settings."""
94+ """Test default settings values ."""
7395 settings = Settings ()
7496 assert settings .sync_remotes is True
7597 assert settings .default_vcs is None
7698 assert settings .depth is None
7799
78100 def test_custom_settings (self ) -> None :
79- """Test custom settings."""
101+ """Test custom settings values ."""
80102 settings = Settings (
81103 sync_remotes = False ,
82104 default_vcs = "git" ,
@@ -88,49 +110,53 @@ def test_custom_settings(self) -> None:
88110
89111
90112class TestVCSPullConfig :
91- """Tests for the VCSPullConfig model."""
113+ """Tests for VCSPullConfig model."""
92114
93115 def test_empty_config (self ) -> None :
94- """Test empty configuration."""
116+ """Test creating an empty configuration."""
95117 config = VCSPullConfig ()
96118 assert isinstance (config .settings , Settings )
97- assert config .repositories == []
98- assert config .includes == []
119+ assert len ( config .repositories ) == 0
120+ assert len ( config .includes ) == 0
99121
100- def test_full_config (self ) -> None :
101- """Test full configuration."""
122+ def test_config_with_repositories (self ) -> None :
123+ """Test creating a configuration with repositories ."""
102124 config = VCSPullConfig (
103- settings = Settings (
104- sync_remotes = False ,
105- default_vcs = "git" ,
106- depth = 1 ,
107- ),
108125 repositories = [
109126 Repository (
110127 name = "repo1" ,
111128 url = "https://github.com/user/repo1.git" ,
112129 path = "~/code/repo1" ,
113- vcs = "git" ,
114130 ),
115131 Repository (
116132 name = "repo2" ,
117133 url = "https://github.com/user/repo2.git" ,
118134 path = "~/code/repo2" ,
119- vcs = "git" ,
120135 ),
121136 ],
122- includes = [
123- "~/other-config.yaml" ,
124- ],
125137 )
126-
127- assert config .settings .sync_remotes is False
128- assert config .settings .default_vcs == "git"
129- assert config .settings .depth == 1
130-
131138 assert len (config .repositories ) == 2
132139 assert config .repositories [0 ].name == "repo1"
133140 assert config .repositories [1 ].name == "repo2"
134141
135- assert len (config .includes ) == 1
136- assert config .includes [0 ] == "~/other-config.yaml"
142+ def test_config_with_includes (self ) -> None :
143+ """Test creating a configuration with includes."""
144+ config = VCSPullConfig (
145+ includes = ["file1.yaml" , "file2.yaml" ],
146+ )
147+ assert len (config .includes ) == 2
148+ assert config .includes [0 ] == "file1.yaml"
149+ assert config .includes [1 ] == "file2.yaml"
150+
151+ def test_config_with_settings (self ) -> None :
152+ """Test creating a configuration with settings."""
153+ config = VCSPullConfig (
154+ settings = Settings (
155+ sync_remotes = False ,
156+ default_vcs = "git" ,
157+ depth = 1 ,
158+ ),
159+ )
160+ assert config .settings .sync_remotes is False
161+ assert config .settings .default_vcs == "git"
162+ assert config .settings .depth == 1
0 commit comments