1
- """Tests for configuration models."""
1
+ """Tests for configuration models.
2
+
3
+ This module contains tests for the VCSPull configuration models.
4
+ """
2
5
3
6
from __future__ import annotations
4
7
5
- from pathlib import Path
8
+ import pathlib
6
9
7
10
import pytest
8
11
from pydantic import ValidationError
11
14
12
15
13
16
class TestRepository :
14
- """Tests for the Repository model."""
17
+ """Tests for Repository model."""
15
18
16
19
def test_minimal_repository (self ) -> None :
17
20
"""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
+ )
19
25
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
21
27
assert repo .vcs is None
22
28
assert repo .name is None
23
- assert repo .remotes == {}
29
+ assert len ( repo .remotes ) == 0
24
30
assert repo .rev is None
25
31
assert repo .web_url is None
26
32
27
33
def test_full_repository (self ) -> None :
28
34
"""Test creating a repository with all fields."""
29
35
repo = Repository (
30
- name = "test-repo " ,
36
+ name = "test" ,
31
37
url = "https://github.com/user/repo.git" ,
32
38
path = "~/code/repo" ,
33
39
vcs = "git" ,
34
40
remotes = {"upstream" : "https://github.com/upstream/repo.git" },
35
41
rev = "main" ,
36
42
web_url = "https://github.com/user/repo" ,
37
43
)
38
- assert repo .name == "test-repo "
44
+ assert repo .name == "test"
39
45
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
41
47
assert repo .vcs == "git"
42
48
assert repo .remotes == {"upstream" : "https://github.com/upstream/repo.git" }
43
49
assert repo .rev == "main"
44
50
assert repo .web_url == "https://github.com/user/repo"
45
51
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
+
46
67
def test_path_validation (self ) -> None :
47
68
"""Test path validation."""
48
69
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
50
72
51
73
def test_missing_required_fields (self ) -> None :
52
74
"""Test validation error when required fields are missing."""
@@ -66,17 +88,17 @@ def test_missing_required_fields(self) -> None:
66
88
67
89
68
90
class TestSettings :
69
- """Tests for the Settings model."""
91
+ """Tests for Settings model."""
70
92
71
93
def test_default_settings (self ) -> None :
72
- """Test default settings."""
94
+ """Test default settings values ."""
73
95
settings = Settings ()
74
96
assert settings .sync_remotes is True
75
97
assert settings .default_vcs is None
76
98
assert settings .depth is None
77
99
78
100
def test_custom_settings (self ) -> None :
79
- """Test custom settings."""
101
+ """Test custom settings values ."""
80
102
settings = Settings (
81
103
sync_remotes = False ,
82
104
default_vcs = "git" ,
@@ -88,49 +110,53 @@ def test_custom_settings(self) -> None:
88
110
89
111
90
112
class TestVCSPullConfig :
91
- """Tests for the VCSPullConfig model."""
113
+ """Tests for VCSPullConfig model."""
92
114
93
115
def test_empty_config (self ) -> None :
94
- """Test empty configuration."""
116
+ """Test creating an empty configuration."""
95
117
config = VCSPullConfig ()
96
118
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
99
121
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 ."""
102
124
config = VCSPullConfig (
103
- settings = Settings (
104
- sync_remotes = False ,
105
- default_vcs = "git" ,
106
- depth = 1 ,
107
- ),
108
125
repositories = [
109
126
Repository (
110
127
name = "repo1" ,
111
128
url = "https://github.com/user/repo1.git" ,
112
129
path = "~/code/repo1" ,
113
- vcs = "git" ,
114
130
),
115
131
Repository (
116
132
name = "repo2" ,
117
133
url = "https://github.com/user/repo2.git" ,
118
134
path = "~/code/repo2" ,
119
- vcs = "git" ,
120
135
),
121
136
],
122
- includes = [
123
- "~/other-config.yaml" ,
124
- ],
125
137
)
126
-
127
- assert config .settings .sync_remotes is False
128
- assert config .settings .default_vcs == "git"
129
- assert config .settings .depth == 1
130
-
131
138
assert len (config .repositories ) == 2
132
139
assert config .repositories [0 ].name == "repo1"
133
140
assert config .repositories [1 ].name == "repo2"
134
141
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