Debian Codegraph @

testsuite/tests/publish/remote-origin-nonstd/test.py

raw
1 """
2 Test proper publishing of a ready remote origin with custom manifest location
3 """
4
5 from drivers.alr import run_alr, index_version
6 from drivers.asserts import assert_match
7 from drivers.helpers import contents, content_of, init_git_repo, zip_dir
8 from shutil import copyfile, rmtree
9 from zipfile import ZipFile
10
11 import os
12
13
14 def verify_manifest():
15 target = os.path.join("alire", "releases", "xxx-0.1.0-dev.toml")
16 assert os.path.isfile(target), \
17 "Index manifest not found at expected location"
18 # Minimally check the expected contents are in the file
19 assert "[origin]" in content_of(target)
20 assert "url" in content_of(target)
21
22 # create and add an index to check the manifest is loadable later on
23 os.makedirs(os.path.join("my_index", "xx", "xxx"))
24 with open(os.path.join("my_index", "index.toml"), "wt") as index_metadata:
25 index_metadata.write(f"version = '{index_version()}'\n")
26 run_alr("index", "--add", "my_index", "--name", "my_index")
27
28 # Prepare a repo and a zipball to be used as "remote" targets for publishing
29 run_alr("init", "--bin", "xxx")
30 # Rename the manifest location
31 os.rename(os.path.join("xxx", "alire.toml"), os.path.join("xxx", "xxx.toml"))
32
33 # Create the zip
34 zip_dir("xxx", "xxx.zip")
35
36 # Create repo with the sources
37 head_commit = init_git_repo("xxx")
38
39 # A "remote" source archive. We force to allow the test to skip the remote
40 # check. Curl requires an absolute path to work.
41 target = os.path.join(os.getcwd(), "xxx.zip")
42 run_alr("publish", f"file:{target}", "--manifest", "xxx.toml", force=True)
43 # Should complete without error, check the generated file is in place
44 verify_manifest()
45
46 # Clean up for the next test
47 rmtree("alire")
48
49 # Same test, using directly the source repository
50 target = os.path.join(os.getcwd(), "xxx")
51 run_alr("publish", f"git+file:{target}", head_commit,
52 "--manifest", "xxx.toml", force=True)
53 verify_manifest()
54
55 # Copy the new index manifest into the index
56 copyfile(os.path.join("alire", "releases", "xxx-0.1.0-dev.toml"),
57 os.path.join("my_index", "xx", "xxx", "xxx-0.1.0-dev.toml"))
58
59 p = run_alr("search", "--crates")
60 assert "xxx" in p.out, "Crate not found in index contents"
61
62 print('SUCCESS')