|
3 | 3 | load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts", "unittest") |
4 | 4 | load("@bazel_skylib//rules:write_file.bzl", "write_file") |
5 | 5 | load("//py/private:providers.bzl", "PyWheelsInfo") |
6 | | -load(":repository.bzl", "compatible_python_tags", "select_key", "sort_select_arms", "source_specificity") |
| 6 | +load(":repository.bzl", "compatible_python_tags", "parse_record_path", "select_key", "sort_select_arms", "source_specificity") |
7 | 7 | load(":rule.bzl", "whl_install") |
8 | 8 |
|
9 | 9 | def _whl_sorting_test_impl(ctx): |
@@ -83,6 +83,51 @@ source_specificity_test = unittest.make( |
83 | 83 | _source_specificity_test_impl, |
84 | 84 | ) |
85 | 85 |
|
| 86 | +def _record_path_test_impl(ctx): |
| 87 | + env = unittest.begin(ctx) |
| 88 | + |
| 89 | + # Unquoted: the common case. |
| 90 | + asserts.equals(env, "plain.py", parse_record_path("plain.py,sha256=abc,1")) |
| 91 | + |
| 92 | + # Quoted because the path contains a comma (the reason a real wheel |
| 93 | + # quotes a RECORD path at all). |
| 94 | + asserts.equals( |
| 95 | + env, |
| 96 | + "pkg/data/sample,1.csv", |
| 97 | + parse_record_path("\"pkg/data/sample,1.csv\",sha256=abc,1"), |
| 98 | + ) |
| 99 | + |
| 100 | + # Quoted with both an embedded comma and a doubled-quote escape ("" -> "). |
| 101 | + asserts.equals( |
| 102 | + env, |
| 103 | + "package/a,b\"c.py", |
| 104 | + parse_record_path("\"package/a,b\"\"c.py\",,"), |
| 105 | + ) |
| 106 | + |
| 107 | + # Empty first field (blank line, or a leading comma) yields no path; the |
| 108 | + # caller skips falsy paths. |
| 109 | + asserts.equals(env, "", parse_record_path("")) |
| 110 | + asserts.equals(env, "", parse_record_path(",sha256=abc,1")) |
| 111 | + |
| 112 | + # Byte-faithful to csv.reader on malformed-but-parseable rows (these don't |
| 113 | + # occur in valid RECORD files, but we match the reader rather than guess): |
| 114 | + # |
| 115 | + # text after a closing quote concatenates literally, |
| 116 | + asserts.equals(env, "abcdef", parse_record_path("\"abc\"def,1")) |
| 117 | + |
| 118 | + # with quotes in that trailing text staying literal, |
| 119 | + asserts.equals(env, "abcdef\"ghi\"", parse_record_path("\"abc\"def\"ghi\",1")) |
| 120 | + |
| 121 | + # a `"` that does not open the field is a literal character, |
| 122 | + asserts.equals(env, "a\"b\"c", parse_record_path("a\"b\"c,1")) |
| 123 | + |
| 124 | + # and an unterminated quote consumes the rest of the row. |
| 125 | + asserts.equals(env, "unterminated,1", parse_record_path("\"unterminated,1")) |
| 126 | + |
| 127 | + return unittest.end(env) |
| 128 | + |
| 129 | +record_path_test = unittest.make(_record_path_test_impl) |
| 130 | + |
86 | 131 | # --- whl_install metadata selection --------------------------------------- |
87 | 132 | # |
88 | 133 | # Regression: the package surface advertised via PyWheelsInfo (top-levels, |
@@ -253,3 +298,7 @@ def whl_install_suite(): |
253 | 298 | "source_specificity_tests", |
254 | 299 | source_specificity_test, |
255 | 300 | ) |
| 301 | + unittest.suite( |
| 302 | + "record_path_tests", |
| 303 | + record_path_test, |
| 304 | + ) |
0 commit comments