Skip to content

Commit 8e2b6de

Browse files
authored
Added tests for additional utilities of pip_install and pip_parse (#524)
1 parent d09d60c commit 8e2b6de

File tree

10 files changed

+177
-54
lines changed

10 files changed

+177
-54
lines changed

examples/pip_install/BUILD

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
22
load("@bazel_skylib//rules:write_file.bzl", "write_file")
33
load(
44
"@pip//:requirements.bzl",
5+
"data_requirement",
6+
"dist_info_requirement",
57
"entry_point",
68
"requirement",
79
)
@@ -55,18 +57,28 @@ alias(
5557
actual = entry_point("yamllint"),
5658
)
5759

58-
py_test(
59-
name = "entry_point_test",
60-
srcs = ["entry_point_test.py"],
61-
data = [":yamllint"],
62-
)
63-
6460
# Check that our compiled requirements are up-to-date
6561
compile_pip_requirements(
6662
name = "requirements",
6763
extra_args = ["--allow-unsafe"],
6864
)
6965

66+
# Test the use of all pip_install utilities in a single py_test
67+
py_test(
68+
name = "pip_install_test",
69+
srcs = ["pip_install_test.py"],
70+
data = [
71+
":yamllint",
72+
data_requirement("s3cmd"),
73+
dist_info_requirement("boto3"),
74+
],
75+
env = {
76+
"WHEEL_DATA_CONTENTS": "$(rootpaths {})".format(data_requirement("s3cmd")),
77+
"WHEEL_DIST_INFO_CONTENTS": "$(rootpaths {})".format(dist_info_requirement("boto3")),
78+
"WHEEL_ENTRY_POINT": "$(rootpath :yamllint)",
79+
},
80+
)
81+
7082
# Assert that tags are present on resulting py_library,
7183
# which is useful for tooling that needs to reflect on the dep graph
7284
# to determine the packages it was built from.

examples/pip_install/entry_point_test.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
import os
5+
import subprocess
6+
import unittest
7+
8+
9+
class PipInstallTest(unittest.TestCase):
10+
maxDiff = None
11+
12+
def test_entry_point(self):
13+
env = os.environ.get("WHEEL_ENTRY_POINT")
14+
self.assertIsNotNone(env)
15+
16+
entry_point = Path(env)
17+
self.assertTrue(entry_point.exists())
18+
19+
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
20+
self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
21+
22+
def test_data(self):
23+
env = os.environ.get("WHEEL_DATA_CONTENTS")
24+
self.assertIsNotNone(env)
25+
self.assertListEqual(
26+
env.split(" "),
27+
[
28+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/INSTALL.md",
29+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/LICENSE",
30+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/NEWS",
31+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/README.md",
32+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/data/share/man/man1/s3cmd.1",
33+
"external/pip/pypi__s3cmd/s3cmd-2.1.0.data/scripts/s3cmd",
34+
],
35+
)
36+
37+
def test_dist_info(self):
38+
env = os.environ.get("WHEEL_DIST_INFO_CONTENTS")
39+
self.assertIsNotNone(env)
40+
self.assertListEqual(
41+
env.split(" "),
42+
[
43+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/DESCRIPTION.rst",
44+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/METADATA",
45+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/RECORD",
46+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/WHEEL",
47+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/metadata.json",
48+
"external/pip/pypi__boto3/boto3-1.14.51.dist-info/top_level.txt",
49+
],
50+
)
51+
52+
53+
if __name__ == "__main__":
54+
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
boto3==1.14.51
22
yamllint==1.26.3
3+
s3cmd==2.1.0

examples/pip_install/requirements.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ pathspec==0.9.0 \
3232
python-dateutil==2.8.2 \
3333
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
3434
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
35-
# via botocore
35+
# via
36+
# botocore
37+
# s3cmd
38+
python-magic==0.4.24 \
39+
--hash=sha256:4fec8ee805fea30c07afccd1592c0f17977089895bdfaae5fec870a84e997626 \
40+
--hash=sha256:de800df9fb50f8ec5974761054a708af6e4246b03b4bdaee993f948947b0ebcf
41+
# via s3cmd
3642
pyyaml==5.4.1 \
3743
--hash=sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf \
3844
--hash=sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696 \
@@ -64,6 +70,10 @@ pyyaml==5.4.1 \
6470
--hash=sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6 \
6571
--hash=sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0
6672
# via yamllint
73+
s3cmd==2.1.0 \
74+
--hash=sha256:49cd23d516b17974b22b611a95ce4d93fe326feaa07320bd1d234fed68cbccfa \
75+
--hash=sha256:966b0a494a916fc3b4324de38f089c86c70ee90e8e1cae6d59102103a4c0cc03
76+
# via -r requirements.in
6777
s3transfer==0.3.7 \
6878
--hash=sha256:35627b86af8ff97e7ac27975fe0a98a312814b46c6333d8a6b889627bcd80994 \
6979
--hash=sha256:efa5bd92a897b6a8d5c1383828dca3d52d0790e0756d49740563a3fb6ed03246

examples/pip_parse/BUILD

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
load("@pip_parsed_deps//:requirements.bzl", "entry_point", "requirement")
1+
load(
2+
"@pip_parsed_deps//:requirements.bzl",
3+
"data_requirement",
4+
"dist_info_requirement",
5+
"entry_point",
6+
"requirement",
7+
)
28
load("@rules_python//python:defs.bzl", "py_binary", "py_test")
39
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
410

@@ -54,16 +60,26 @@ alias(
5460
),
5561
)
5662

57-
py_test(
58-
name = "entry_point_test",
59-
srcs = ["entry_point_test.py"],
60-
data = [":yamllint"],
61-
)
62-
6363
# This rule adds a convenient way to update the requiremenst file.
6464
compile_pip_requirements(
6565
name = "requirements",
6666
extra_args = ["--allow-unsafe"],
6767
requirements_in = "requirements.txt",
6868
requirements_txt = "requirements_lock.txt",
6969
)
70+
71+
# Test the use of all pip_parse utilities in a single py_test
72+
py_test(
73+
name = "pip_parse_test",
74+
srcs = ["pip_parse_test.py"],
75+
data = [
76+
":yamllint",
77+
data_requirement("s3cmd"),
78+
dist_info_requirement("requests"),
79+
],
80+
env = {
81+
"WHEEL_DATA_CONTENTS": "$(rootpaths {})".format(data_requirement("s3cmd")),
82+
"WHEEL_DIST_INFO_CONTENTS": "$(rootpaths {})".format(dist_info_requirement("requests")),
83+
"WHEEL_ENTRY_POINT": "$(rootpath :yamllint)",
84+
},
85+
)

examples/pip_parse/entry_point_test.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
from pathlib import Path
4+
import os
5+
import subprocess
6+
import unittest
7+
8+
9+
class PipInstallTest(unittest.TestCase):
10+
maxDiff = None
11+
12+
def test_entry_point(self):
13+
env = os.environ.get("WHEEL_ENTRY_POINT")
14+
self.assertIsNotNone(env)
15+
16+
entry_point = Path(env)
17+
self.assertTrue(entry_point.exists())
18+
19+
proc = subprocess.run([entry_point, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
20+
self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
21+
22+
def test_data(self):
23+
env = os.environ.get("WHEEL_DATA_CONTENTS")
24+
self.assertIsNotNone(env)
25+
self.assertListEqual(
26+
env.split(" "),
27+
[
28+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/INSTALL.md",
29+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/LICENSE",
30+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/NEWS",
31+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/data/share/doc/packages/s3cmd/README.md",
32+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/data/share/man/man1/s3cmd.1",
33+
"external/pip_parsed_deps_pypi__s3cmd/s3cmd-2.1.0.data/scripts/s3cmd",
34+
],
35+
)
36+
37+
def test_dist_info(self):
38+
env = os.environ.get("WHEEL_DIST_INFO_CONTENTS")
39+
self.assertIsNotNone(env)
40+
self.assertListEqual(
41+
env.split(" "),
42+
[
43+
"external/pip_parsed_deps_pypi__requests/requests-2.25.1.dist-info/LICENSE",
44+
"external/pip_parsed_deps_pypi__requests/requests-2.25.1.dist-info/METADATA",
45+
"external/pip_parsed_deps_pypi__requests/requests-2.25.1.dist-info/RECORD",
46+
"external/pip_parsed_deps_pypi__requests/requests-2.25.1.dist-info/WHEEL",
47+
"external/pip_parsed_deps_pypi__requests/requests-2.25.1.dist-info/top_level.txt",
48+
],
49+
)
50+
51+
52+
if __name__ == "__main__":
53+
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests==2.25.1
22
yamllint==1.26.3
3+
s3cmd==2.1.0

examples/pip_parse/requirements_lock.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ pathspec==0.9.0 \
2020
--hash=sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a \
2121
--hash=sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1
2222
# via yamllint
23+
python-dateutil==2.8.2 \
24+
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
25+
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
26+
# via s3cmd
27+
python-magic==0.4.24 \
28+
--hash=sha256:4fec8ee805fea30c07afccd1592c0f17977089895bdfaae5fec870a84e997626 \
29+
--hash=sha256:de800df9fb50f8ec5974761054a708af6e4246b03b4bdaee993f948947b0ebcf
30+
# via s3cmd
2331
pyyaml==5.4.1 \
2432
--hash=sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf \
2533
--hash=sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696 \
@@ -55,6 +63,14 @@ requests==2.25.1 \
5563
--hash=sha256:27973dd4a904a4f13b263a19c866c13b92a39ed1c964655f025f3f8d3d75b804 \
5664
--hash=sha256:c210084e36a42ae6b9219e00e48287def368a26d03a048ddad7bfee44f75871e
5765
# via -r requirements.txt
66+
s3cmd==2.1.0 \
67+
--hash=sha256:49cd23d516b17974b22b611a95ce4d93fe326feaa07320bd1d234fed68cbccfa \
68+
--hash=sha256:966b0a494a916fc3b4324de38f089c86c70ee90e8e1cae6d59102103a4c0cc03
69+
# via -r requirements.txt
70+
six==1.16.0 \
71+
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
72+
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
73+
# via python-dateutil
5874
urllib3==1.26.5 \
5975
--hash=sha256:753a0374df26658f99d826cfe40394a686d05985786d946fbe4165b5148f5a7c \
6076
--hash=sha256:a7acd0977125325f516bda9735fa7142b909a8d01e8b2e4c8108d0984e6e0098

0 commit comments

Comments
 (0)