-
Notifications
You must be signed in to change notification settings - Fork 946
/
install_test.py
467 lines (399 loc) · 20.8 KB
/
install_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
import os
import textwrap
from collections import OrderedDict
import pytest
from conans.model.ref import ConanFileReference
from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID
from conans.test.utils.tools import TestClient, TestServer, GenConanfile
from conans.util.files import mkdir, rmdir, save
@pytest.fixture()
def client():
c = TestClient(default_server_user=True)
save(c.cache.settings_path, "os: [Windows, Macos, Linux, FreeBSD]\nos_build: [Windows, Macos]")
save(c.cache.default_profile_path, "[settings]\nos=Windows")
return c
def test_not_found_package_dirty_cache(client):
# Conan does a lock on the cache, and even if the package doesn't exist
# left a trailing folder with the filelocks. This test checks
# it will be cleared
client.save({"conanfile.py": GenConanfile("Hello", "0.1")})
client.run("create . lasote/testing")
client.run("upload * --all --confirm")
client.run('remove "*" -f')
client.run(" install hello/0.1@lasote/testing", assert_error=True)
assert "Unable to find 'hello/0.1@lasote/testing'" in client.out
# This used to fail in Windows, because of the trailing lock
client.run("remove * -f")
client.run(" install Hello/0.1@lasote/testing")
def test_install_reference_txt(client):
# Test to check the "conan install <path> <reference>" command argument
client.save({"conanfile.txt": ""})
client.run("info .")
assert "conanfile.txt" in str(client.out).splitlines()
def test_install_reference_error(client):
# Test to check the "conan install <path> <reference>" command argument
client.run("install Pkg/0.1@myuser/testing user/testing", assert_error=True)
assert "ERROR: A full reference was provided as first argument" in client.out
def test_install_reference(client):
# Test to check the "conan install <path> <reference>" command argument
conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
def build(self):
self.output.info("REF: %s, %s, %s, %s"
% (self.name, self.version, self.user, self.channel))
""")
client.save({"conanfile.py": conanfile})
client.run(" install . Pkg/0.1@myuser/testing")
client.run(" info .")
assert "Pkg/0.1@myuser/testing" in client.out
client.run("build .")
assert "REF: Pkg, 0.1, myuser, testing" in client.out
# Trying with partial name
conanfile = conanfile + " name = 'Other'\n"
client.save({"conanfile.py": conanfile})
# passing the wrong package name raises
client.run(" install . Pkg/0.1@myuser/testing", assert_error=True)
assert "ERROR: Package recipe with name Pkg!=Other" in client.out
# Partial reference works
client.run(" install . 0.1@myuser/testing")
client.run("build .")
assert "REF: Other, 0.1, myuser, testing" in client.out
# And also full reference matching
client.run(" install . Other/0.1@myuser/testing")
client.run("build .")
assert "REF: Other, 0.1, myuser, testing" in client.out
# Trying with partial name and version
conanfile = conanfile + " version = '0.2'\n"
client.save({"conanfile.py": conanfile})
# passing the wrong package name raises
client.run(" install . Other/0.1@myuser/testing", assert_error=True)
assert "ERROR: Package recipe with version 0.1!=0.2" in client.out
# Partial reference works
client.run(" install . myuser/testing")
client.run("build .")
assert "REF: Other, 0.2, myuser, testing" in client.out
# And also full reference matching
client.run(" install . Other/0.2@myuser/testing")
client.run("build .")
assert "REF: Other, 0.2, myuser, testing" in client.out
def test_four_subfolder_install(client):
# https://github.com/conan-io/conan/issues/3950
client.save({"path/to/sub/folder/conanfile.txt": ""})
# If this doesn't, fail, all good
client.run(" install path/to/sub/folder")
def test_install_system_requirements(client):
client.save({"conanfile.py": textwrap.dedent("""
from conans import ConanFile
class MyPkg(ConanFile):
def system_requirements(self):
self.output.info("Running system requirements!!")
""")})
client.run(" install .")
assert "Running system requirements!!" in client.out
client.run("export . Pkg/0.1@lasote/testing")
client.run(" install Pkg/0.1@lasote/testing --build")
assert "Running system requirements!!" in client.out
client.run("upload * --all --confirm")
client.run('remove "*" -f')
client.run(" install Pkg/0.1@lasote/testing")
assert "Running system requirements!!" in client.out
def test_install_transitive_pattern(client):
# Make sure a simple conan install doesn't fire package_info() so self.package_folder breaks
client.save({"conanfile.py": textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
options = {"shared": [True, False, "header"]}
default_options = "shared=False"
def package_info(self):
self.output.info("PKG OPTION: %s" % self.options.shared)
""")})
client.run("create . Pkg/0.1@user/testing -o shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
client.save({"conanfile.py": textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
requires = "Pkg/0.1@user/testing"
options = {"shared": [True, False, "header"]}
default_options = "shared=False"
def package_info(self):
self.output.info("PKG2 OPTION: %s" % self.options.shared)
""")})
client.run("create . Pkg2/0.1@user/testing -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: True" in client.out
client.run(" install Pkg2/0.1@user/testing -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: True" in client.out
# Priority of non-scoped options
client.run("create . Pkg2/0.1@user/testing -o shared=header -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
client.run(" install Pkg2/0.1@user/testing -o shared=header -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
# Prevalence of exact named option
client.run("create . Pkg2/0.1@user/testing -o *:shared=True -o Pkg2:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
client.run(" install Pkg2/0.1@user/testing -o *:shared=True -o Pkg2:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
# Prevalence of exact named option reverse
client.run("create . Pkg2/0.1@user/testing -o *:shared=True -o Pkg:shared=header "
"--build=missing")
assert "Pkg/0.1@user/testing: Calling build()" in client.out
assert "Pkg/0.1@user/testing: PKG OPTION: header" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: True" in client.out
client.run(" install Pkg2/0.1@user/testing -o *:shared=True -o Pkg:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: header" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: True" in client.out
# Prevalence of alphabetical pattern
client.run("create . Pkg2/0.1@user/testing -o *:shared=True -o Pkg2*:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
client.run(" install Pkg2/0.1@user/testing -o *:shared=True -o Pkg2*:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
# Prevalence of alphabetical pattern, opposite order
client.run("create . Pkg2/0.1@user/testing -o Pkg2*:shared=header -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
client.run(" install Pkg2/0.1@user/testing -o Pkg2*:shared=header -o *:shared=True")
assert "Pkg/0.1@user/testing: PKG OPTION: True" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
# Prevalence and override of alphabetical pattern
client.run("create . Pkg2/0.1@user/testing -o *:shared=True -o Pkg*:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: header" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
client.run(" install Pkg2/0.1@user/testing -o *:shared=True -o Pkg*:shared=header")
assert "Pkg/0.1@user/testing: PKG OPTION: header" in client.out
assert "Pkg2/0.1@user/testing: PKG2 OPTION: header" in client.out
def test_install_package_folder(client):
# Make sure a simple conan install doesn't fire package_info() so self.package_folder breaks
client.save({"conanfile.py": textwrap.dedent("""\
from conans import ConanFile
import os
class Pkg(ConanFile):
def package_info(self):
self.dummy_doesnt_exist_not_break
self.output.info("Hello")
self.env_info.PATH = os.path.join(self.package_folder, "bin")
""")})
client.run(" install .")
assert "Hello" not in client.out
assert "conanfile.py: Generated conaninfo.txt" in client.out
def test_install_cwd(client):
client.save({"conanfile.py": GenConanfile("Hello", "0.1").with_setting("os")})
client.run("export . lasote/stable")
client.save({"conanfile.txt": "[requires]\nHello/0.1@lasote/stable"}, clean_first=True)
client.run("install . --build=missing -s os_build=Windows --install-folder=win_dir")
assert "Hello/0.1@lasote/stable from local cache" in client.out
client.run("install . --build=missing -s os=Macos -s os_build=Macos "
"--install-folder=os_dir")
conaninfo = client.load("win_dir/conaninfo.txt")
assert "os=Windows" in conaninfo
assert "os=Macos" not in conaninfo
conaninfo = client.load("os_dir/conaninfo.txt")
assert "os=Windows" not in conaninfo
assert "os=Macos" in conaninfo
def test_install_reference_not_conanbuildinfo(client):
client.save({"conanfile.py": GenConanfile("Hello", "0.1").with_setting("os")})
client.run("create . conan/stable")
client.save({}, clean_first=True)
client.run("install Hello/0.1@conan/stable")
assert not os.path.exists(os.path.join(client.current_folder, "conanbuildinfo.txt"))
def test_install_with_profile(client):
# Test for https://github.com/conan-io/conan/pull/2043
conanfile = textwrap.dedent("""
from conans import ConanFile
class TestConan(ConanFile):
settings = "os"
def requirements(self):
self.output.info("PKGOS=%s" % self.settings.os)
""")
client.save({"conanfile.py": conanfile})
client.run("profile new myprofile")
client.run("profile update settings.os=Linux myprofile")
client.run("install . -pr=myprofile --build")
assert "PKGOS=Linux" in client.out
mkdir(os.path.join(client.current_folder, "myprofile"))
client.run("install . -pr=myprofile")
client.run("profile new myotherprofile")
client.run("profile update settings.os=FreeBSD myotherprofile")
client.run("install . -pr=myotherprofile")
assert "PKGOS=FreeBSD" in client.out
client.save({"myotherprofile": "Some garbage without sense [garbage]"})
client.run("install . -pr=myotherprofile")
assert "PKGOS=FreeBSD" in client.out
client.run("install . -pr=./myotherprofile", assert_error=True)
assert "Error while parsing line 0" in client.out
def test_install_with_path_errors(client):
# Install without path param not allowed
client.run("install", assert_error=True)
assert "ERROR: Exiting with code: 2" in client.out
# Path with wrong conanfile.txt path
client.run("install not_real_dir/conanfile.txt --install-folder subdir", assert_error=True)
assert "Conanfile not found" in client.out
# Path with wrong conanfile.py path
client.run("install not_real_dir/conanfile.py --install-folder build", assert_error=True)
assert "Conanfile not found" in client.out
def test_install_broken_reference(client):
client.save({"conanfile.py": GenConanfile()})
client.run("export . Hello/0.1@lasote/stable")
client.run("remote add_ref Hello/0.1@lasote/stable default")
ref = ConanFileReference.loads("Hello/0.1@lasote/stable")
# Because the folder is removed, the metadata is removed and the
# origin remote is lost
rmdir(os.path.join(client.cache.package_layout(ref).base_folder()))
client.run("install Hello/0.1@lasote/stable", assert_error=True)
assert "ERROR: Unable to find 'Hello/0.1@lasote/stable' in remotes" in client.out
# If it was associated, it has to be desasociated
client.run("remote remove_ref Hello/0.1@lasote/stable")
client.run("install Hello/0.1@lasote/stable", assert_error=True)
assert "ERROR: Unable to find 'Hello/0.1@lasote/stable' in remotes" in client.out
def test_install_argument_order(client):
# https://github.com/conan-io/conan/issues/2520
conanfile_boost = textwrap.dedent("""
from conans import ConanFile
class BoostConan(ConanFile):
name = "boost"
version = "0.1"
options = {"shared": [True, False]}
default_options = "shared=True"
""")
conanfile = GenConanfile().with_require("boost/0.1@conan/stable")
client.save({"conanfile.py": conanfile,
"conanfile_boost.py": conanfile_boost})
client.run("create conanfile_boost.py conan/stable")
client.run("install . -o boost:shared=True --build=missing")
output_0 = "%s" % client.out
client.run("install . -o boost:shared=True --build missing")
output_1 = "%s" % client.out
client.run("install -o boost:shared=True . --build missing")
output_2 = "%s" % client.out
client.run("install -o boost:shared=True --build missing .")
output_3 = "%s" % client.out
assert "ERROR" not in output_3
assert output_0 == output_1
assert output_1 == output_2
assert output_2 == output_3
client.run("install -o boost:shared=True --build boost . --build missing")
output_4 = "%s" % client.out
client.run("install -o boost:shared=True --build missing --build boost .")
output_5 = "%s" % client.out
assert output_4 == output_5
def test_install_anonymous(client):
# https://github.com/conan-io/conan/issues/4871
client.save({"conanfile.py": GenConanfile("Pkg", "0.1")})
client.run("create . lasote/testing")
client.run("upload * --confirm --all")
client2 = TestClient(servers=client.servers, users={})
client2.run("install Pkg/0.1@lasote/testing")
assert "Pkg/0.1@lasote/testing: Package installed" in client2.out
def test_install_without_ref(client):
client.save({"conanfile.py": GenConanfile("lib", "1.0")})
client.run('create .')
assert "lib/1.0: Package '{}' created".format(NO_SETTINGS_PACKAGE_ID) in client.out
client.run('upload lib/1.0 -c --all')
assert "Uploaded conan recipe 'lib/1.0' to 'default'" in client.out
client.run('remove "*" -f')
# This fails, Conan thinks this is a path
client.run('install lib/1.0', assert_error=True)
fake_path = os.path.join(client.current_folder, "lib", "1.0")
assert "Conanfile not found at {}".format(fake_path) in client.out
# Try this syntax to upload too
client.run('install lib/1.0@')
client.run('upload lib/1.0@ -c --all')
def test_install_disabled_remote(client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . Pkg/0.1@lasote/testing")
client.run("upload * --confirm --all -r default")
client.run("remote disable default")
client.run("install Pkg/0.1@lasote/testing -r default")
assert "Pkg/0.1@lasote/testing: Already installed!" in client.out
client.run("remote enable default")
client.run("install Pkg/0.1@lasote/testing -r default")
client.run("remote disable default")
client.run("install Pkg/0.1@lasote/testing --update", assert_error=True)
assert "ERROR: Remote 'default' is disabled" in client.out
def test_install_skip_disabled_remote():
client = TestClient(servers=OrderedDict({"default": TestServer(),
"server2": TestServer(),
"server3": TestServer()}),
users={"default": [("lasote", "mypass")],
"server3": [("lasote", "mypass")]})
client.save({"conanfile.py": GenConanfile()})
client.run("create . Pkg/0.1@lasote/testing")
client.run("upload * --confirm --all -r default")
client.run("upload * --confirm --all -r server3")
client.run("remove * -f")
client.run("remote disable default")
client.run("install Pkg/0.1@lasote/testing", assert_error=False)
assert "Trying with 'default'..." not in client.out
def test_install_without_update_fail(client):
# https://github.com/conan-io/conan/issues/9183
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("upload * --confirm --all -r default")
client.save({"conanfile.py": GenConanfile().with_requires("zlib/1.0")})
client.run("remote disable default")
client.run("install .")
assert "zlib/1.0: Already installed" in client.out
def test_install_version_range_reference(client):
# https://github.com/conan-io/conan/issues/5905
client.save({"conanfile.py": GenConanfile()})
client.run("create . pkg/0.1@user/channel")
client.run("install pkg/[*]@user/channel")
assert "pkg/0.1@user/channel from local cache - Cache" in client.out
client.run("install pkg/[0.*]@user/channel")
assert "pkg/0.1@user/channel from local cache - Cache" in client.out
def test_install_error_never(client):
client.save({"conanfile.py": GenConanfile("Hello0", "0.1")})
client.run("create .")
client.run("install . --build never --build missing", assert_error=True)
assert "ERROR: --build=never not compatible with other options" in client.out
client.run("install conanfile.py --build never --build Hello", assert_error=True)
assert "ERROR: --build=never not compatible with other options" in client.out
client.run("install ./conanfile.py --build never --build outdated", assert_error=True)
assert "ERROR: --build=never not compatible with other options" in client.out
class TestCliOverride:
def test_install_cli_override(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("create . zlib/2.0@")
client.save({"conanfile.py": GenConanfile().with_requires("zlib/1.0")})
client.run("install . --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out
def test_install_ref_cli_override(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("create . zlib/1.1@")
client.save({"conanfile.py": GenConanfile().with_requires("zlib/1.0")})
client.run("create . pkg/1.0@")
client.run("install pkg/1.0@ --require-override=zlib/1.1")
assert "zlib/1.1: Already installed" in client.out
def test_create_cli_override(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("create . zlib/2.0@")
client.save({"conanfile.py": GenConanfile().with_requires("zlib/1.0"),
"test_package/conanfile.py": GenConanfile().with_test("pass")})
client.run("create . pkg/0.1@ --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out
def test_install_bintray_warning():
server = TestServer(complete_urls=True)
from conans.client.graph import proxy
proxy.DEPRECATED_CONAN_CENTER_BINTRAY_URL = server.fake_url # Mocking!
client = TestClient(servers={"conan-center": server},
users={"conan-center": [("lasote", "mypass")]})
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@lasote/testing")
client.run("upload zlib/1.0@lasote/testing --all -r conan-center")
client.run("remove * -f")
client.run("install zlib/1.0@lasote/testing -r conan-center")
assert "WARN: Remote https://conan.bintray.com is deprecated and will be shut down " \
"soon" in client.out
client.run("install zlib/1.0@lasote/testing -r conan-center -s build_type=Debug")
assert "WARN: Remote https://conan.bintray.com is deprecated and will be shut down " \
"soon" not in client.out