|
| 1 | +"" |
| 2 | + |
| 3 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
| 4 | +load("//python/private/pypi:argparse.bzl", "argparse") # buildifier: disable=bzl-visibility |
| 5 | + |
| 6 | +_tests = [] |
| 7 | + |
| 8 | +def _test_index_url(env): |
| 9 | + env.expect.that_str(argparse.index_url([], "default")).equals("default") |
| 10 | + env.expect.that_str(argparse.index_url([], None)).equals(None) |
| 11 | + |
| 12 | + env.expect.that_str(argparse.index_url(["-i", "https://example.com/simple"], "default")).equals("https://example.com/simple") |
| 13 | + env.expect.that_str(argparse.index_url(["--index-url", "https://example.com/simple"], "default")).equals("https://example.com/simple") |
| 14 | + env.expect.that_str(argparse.index_url(["--index-url=https://example.com/simple"], "default")).equals("https://example.com/simple") |
| 15 | + |
| 16 | + env.expect.that_str(argparse.index_url(["--extra-index-url", "https://extra.com", "-i", "https://index.com"], "default")).equals("https://index.com") |
| 17 | + |
| 18 | +_tests.append(_test_index_url) |
| 19 | + |
| 20 | +def _test_extra_index_url(env): |
| 21 | + env.expect.that_collection(argparse.extra_index_url([], ["default"])).contains_exactly(["default"]) |
| 22 | + env.expect.that_collection(argparse.extra_index_url([], None)).contains_exactly([]) |
| 23 | + |
| 24 | + env.expect.that_collection(argparse.extra_index_url(["--extra-index-url", "https://extra.com/simple"], [])).contains_exactly(["https://extra.com/simple"]) |
| 25 | + env.expect.that_collection(argparse.extra_index_url(["--extra-index-url=https://extra.com/simple"], [])).contains_exactly(["https://extra.com/simple"]) |
| 26 | + |
| 27 | + env.expect.that_collection(argparse.extra_index_url(["--extra-index-url", "https://first.com", "--extra-index-url", "https://second.com"], [])).contains_exactly(["https://first.com", "https://second.com"]) |
| 28 | + |
| 29 | +_tests.append(_test_extra_index_url) |
| 30 | + |
| 31 | +def _test_platform(env): |
| 32 | + env.expect.that_collection(argparse.platform([], ["default"])).contains_exactly(["default"]) |
| 33 | + env.expect.that_collection(argparse.platform([], None)).contains_exactly([]) |
| 34 | + |
| 35 | + env.expect.that_collection(argparse.platform(["--platform", "manylinux_2_17_x86_64"], [])).contains_exactly(["manylinux_2_17_x86_64"]) |
| 36 | + env.expect.that_collection(argparse.platform(["--platform=manylinux_2_17_x86_64"], [])).contains_exactly(["manylinux_2_17_x86_64"]) |
| 37 | + |
| 38 | + env.expect.that_collection(argparse.platform(["--platform", "macosx_10_9_x86_64", "--platform", "linux_x86_64"], [])).contains_exactly(["macosx_10_9_x86_64", "linux_x86_64"]) |
| 39 | + |
| 40 | +_tests.append(_test_platform) |
| 41 | + |
| 42 | +def argparse_test_suite(name): |
| 43 | + """Create the test suite. |
| 44 | +
|
| 45 | + Args: |
| 46 | + name: the name of the test suite |
| 47 | + """ |
| 48 | + test_suite(name = name, basic_tests = _tests) |
0 commit comments