3
3
# This work is licensed under the terms of the BSD-3-Clause license.
4
4
# For a copy, see <https://opensource.org/license/bsd-3-clause>.
5
5
6
- import json
7
6
from collections .abc import Generator
8
- from dataclasses import dataclass
9
7
from pathlib import Path
10
8
from textwrap import dedent
11
9
from unittest .mock import AsyncMock , MagicMock , patch
12
10
13
11
import pytest
14
12
15
- from cpp_dev .dependency .conan .command_wrapper import (conan_create ,
13
+ from cpp_dev .dependency .conan .command_wrapper import (ConanCommandException ,
14
+ ConanSetting ,
15
+ conan_create ,
16
16
conan_graph_buildorder ,
17
17
conan_list ,
18
18
conan_remote_login ,
19
19
conan_upload )
20
20
from cpp_dev .dependency .conan .setup import CONAN_REMOTE
21
21
from cpp_dev .dependency .conan .types import ConanPackageReference
22
- from cpp_dev .dependency .conan .utils import conan_env
23
22
24
23
from .utils .env import ConanTestEnv , ConanTestPackage , create_conan_test_env
25
- from .utils .server import ConanServer , launch_conan_test_server
24
+ from .utils .server import launch_conan_test_server
26
25
27
26
MockType = MagicMock | AsyncMock
28
27
@@ -31,28 +30,20 @@ def patched_run_command_assert_success() -> Generator[MockType]:
31
30
with patch ("cpp_dev.dependency.conan.command_wrapper.run_command_assert_success" ) as mock_run_command :
32
31
yield mock_run_command
33
32
34
- def test_conan_remote_login (patched_run_command_assert_success : MockType ) -> None :
35
- conan_remote_login (CONAN_REMOTE , "user" , "password" )
36
- patched_run_command_assert_success .assert_called_once_with (
37
- "conan" ,
38
- "remote" ,
39
- "login" ,
40
- CONAN_REMOTE ,
41
- "user" ,
42
- "-p" ,
43
- "password" ,
44
- )
45
-
46
33
def test_conan_create (patched_run_command_assert_success : MockType ) -> None :
47
- conan_create (Path ("package_dir" ), "profile" )
34
+ # todo: this test currently uses a mock, but wil later be changed to test with a real server.
35
+ conan_create (Path ("package_dir" ), "profile" , {"compiler" : "test" , "compiler.cppstd" : "c++17" })
48
36
patched_run_command_assert_success .assert_called_once_with (
49
37
"conan" ,
50
38
"create" ,
51
39
"package_dir" ,
52
40
"-pr:a" , "profile" ,
41
+ "-s:a" , "compiler=test" ,
42
+ "-s:a" , "compiler.cppstd=c++17" ,
53
43
)
54
44
55
45
def test_conan_upload (patched_run_command_assert_success : MockType ) -> None :
46
+ # todo: this test currently uses a mock, but wil later be changed to test with a real server.
56
47
package_ref = ConanPackageReference ("cpd/1.0.0@official/cppdev" )
57
48
conan_upload (package_ref , CONAN_REMOTE )
58
49
patched_run_command_assert_success .assert_called_once_with (
@@ -73,7 +64,7 @@ def conan_test_environment(tmp_path: Path, unused_http_port: int) -> Generator[C
73
64
cpp_standard = "c++17" ,
74
65
),
75
66
ConanTestPackage (
76
- ref = ConanPackageReference ("cpd1/1 .0.0@official/cppdev" ),
67
+ ref = ConanPackageReference ("dep/2 .0.0@official/cppdev" ),
77
68
dependencies = [],
78
69
cpp_standard = "c++17" ,
79
70
),
@@ -82,10 +73,19 @@ def conan_test_environment(tmp_path: Path, unused_http_port: int) -> Generator[C
82
73
dependencies = [ConanPackageReference ("dep/1.0.0@official/cppdev" )],
83
74
cpp_standard = "c++17" ,
84
75
),
76
+ ConanTestPackage (
77
+ ref = ConanPackageReference ("cpd1/1.0.0@official/cppdev" ),
78
+ dependencies = [ConanPackageReference ("dep/2.0.0@official/cppdev" )],
79
+ cpp_standard = "c++17" ,
80
+ ),
85
81
]
86
82
with create_conan_test_env (tmp_path / "conan" , server .http_port , TEST_PACKAGES ) as conan_test_env :
87
83
yield conan_test_env
88
84
85
+ @pytest .mark .conan_remote
86
+ def test_conan_remote_login (conan_test_environment : ConanTestEnv ) -> None :
87
+ conan_remote_login (CONAN_REMOTE , conan_test_environment .server .user , conan_test_environment .server .password )
88
+
89
89
90
90
@pytest .mark .conan_remote
91
91
@pytest .mark .usefixtures ("conan_test_environment" )
@@ -95,6 +95,9 @@ def test_conan_list() -> None:
95
95
assert ConanPackageReference ("cpd/1.0.0@official/cppdev" ) in result
96
96
97
97
98
+ def _construct_settings (test_env : ConanTestEnv ) -> dict [ConanSetting , object ]:
99
+ return {"compiler" : test_env .compiler , "compiler.cppstd" : test_env .cppstd }
100
+
98
101
@pytest .mark .conan_remote
99
102
def test_conan_graph_buildorder (tmp_path : Path , conan_test_environment : ConanTestEnv ) -> None :
100
103
conanfile_path = tmp_path / "conanfile.txt"
@@ -103,7 +106,7 @@ def test_conan_graph_buildorder(tmp_path: Path, conan_test_environment: ConanTes
103
106
cpd/1.0.0@official/cppdev
104
107
""" )
105
108
)
106
- graph_build_order = conan_graph_buildorder (conanfile_path , conan_test_environment .profile )
109
+ graph_build_order = conan_graph_buildorder (conanfile_path , conan_test_environment .profile , _construct_settings ( conan_test_environment ) )
107
110
assert len (graph_build_order .order ) == 2
108
111
assert len (graph_build_order .order [0 ]) == 1
109
112
dep_recipe = graph_build_order .order [0 ][0 ]
@@ -116,3 +119,28 @@ def test_conan_graph_buildorder(tmp_path: Path, conan_test_environment: ConanTes
116
119
assert cpd_recipe .depends [0 ].startswith ("dep/1.0.0@official/cppdev" )
117
120
118
121
122
+ @pytest .mark .conan_remote
123
+ def test_conan_graph_buildorder_dependency_does_not_exist (tmp_path : Path , conan_test_environment : ConanTestEnv ) -> None :
124
+ conanfile_path = tmp_path / "conanfile.txt"
125
+ conanfile_path .write_text (dedent ("""
126
+ [requires]
127
+ cpd/0.0.0@official/cppdev
128
+ """ )
129
+ )
130
+
131
+ with pytest .raises (ConanCommandException , match = "unable to find package" ) as e :
132
+ conan_graph_buildorder (conanfile_path , conan_test_environment .profile , _construct_settings (conan_test_environment ))
133
+
134
+
135
+ @pytest .mark .conan_remote
136
+ def test_conan_graph_buildorder_multiple_dependencies (tmp_path : Path , conan_test_environment : ConanTestEnv ) -> None :
137
+ conanfile_path = tmp_path / "conanfile.txt"
138
+ conanfile_path .write_text (dedent ("""
139
+ [requires]
140
+ cpd/[>=0.0.0]@official/cppdev
141
+ cpd1/[<2.0.0]@official/cppdev
142
+ """ )
143
+ )
144
+
145
+ with pytest .raises (ConanCommandException , match = "version conflict" ) as e :
146
+ conan_graph_buildorder (conanfile_path , conan_test_environment .profile , _construct_settings (conan_test_environment ))
0 commit comments