33# mypy: ignore-errors
44# flake8: noqa
55
6- from unittest .mock import MagicMock , Mock , patch
6+ from typing import Optional
7+ from unittest .mock import patch
78
89import pytest
910
@@ -95,7 +96,11 @@ def get_default_branch(self):
9596 ],
9697)
9798def test_check_wanted_with_local (
98- name , given_on_disk , given_wanted , expect_wanted , expect_have
99+ name : str ,
100+ given_on_disk : Version | None ,
101+ given_wanted : Version ,
102+ expect_wanted : Version ,
103+ expect_have : Version | None ,
99104):
100105 with patch ("dfetch.project.vcs.os.path.exists" ) as mocked_path_exists :
101106 with patch ("dfetch.project.vcs.Metadata.from_file" ) as mocked_metadata :
@@ -120,7 +125,9 @@ def test_check_wanted_with_local(
120125 ("same-hash" , "1234" , "1234" , False ),
121126 ],
122127)
123- def test_are_there_local_changes (name , hash_in_metadata , current_hash , expectation ):
128+ def test_are_there_local_changes (
129+ name : str , hash_in_metadata : str , current_hash : str , expectation : bool
130+ ):
124131 with patch ("dfetch.project.vcs.hash_directory" ) as mocked_hash_directory :
125132 with patch ("dfetch.project.vcs.VCS._on_disk_hash" ) as mocked_on_disk_hash :
126133 vcs = ConcreteVCS (ProjectEntry ({"name" : "proj1" }))
@@ -129,3 +136,28 @@ def test_are_there_local_changes(name, hash_in_metadata, current_hash, expectati
129136 mocked_hash_directory .return_value = current_hash
130137
131138 assert expectation == vcs ._are_there_local_changes ()
139+
140+
141+ @pytest .mark .parametrize (
142+ "ci_env_value, expected_result" ,
143+ [
144+ ("true" , True ),
145+ ("1" , True ),
146+ ("True" , True ),
147+ ("yes" , True ),
148+ ("YES" , True ),
149+ ("false" , False ),
150+ (None , False ),
151+ (0 , False ),
152+ ("other" , False ),
153+ ],
154+ )
155+ def test_ci_enabled (
156+ monkeypatch : pytest .MonkeyPatch , ci_env_value : Optional [str ], expected_result : bool
157+ ):
158+ if ci_env_value is None :
159+ monkeypatch .delenv ("CI" , raising = False )
160+ else :
161+ monkeypatch .setenv ("CI" , ci_env_value )
162+
163+ assert ConcreteVCS ._running_in_ci () == expected_result
0 commit comments