Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "android/soong/python" |
| 7 | ) |
| 8 | |
| 9 | func TestPythonLibrarySimple(t *testing.T) { |
| 10 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
| 11 | description: "simple python_library converts to a native py_library", |
| 12 | moduleTypeUnderTest: "python_library", |
| 13 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 14 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
| 15 | filesystem: map[string]string{ |
| 16 | "a.py": "", |
| 17 | "b/c.py": "", |
| 18 | "b/d.py": "", |
| 19 | "b/e.py": "", |
| 20 | "files/data.txt": "", |
| 21 | }, |
| 22 | blueprint: `python_library { |
| 23 | name: "foo", |
| 24 | srcs: ["**/*.py"], |
| 25 | exclude_srcs: ["b/e.py"], |
| 26 | data: ["files/data.txt",], |
| 27 | bazel_module: { bp2build_available: true }, |
| 28 | } |
| 29 | `, |
| 30 | expectedBazelTargets: []string{`py_library( |
| 31 | name = "foo", |
| 32 | data = ["files/data.txt"], |
| 33 | srcs = [ |
| 34 | "a.py", |
| 35 | "b/c.py", |
| 36 | "b/d.py", |
| 37 | ], |
| 38 | srcs_version = "PY3", |
| 39 | )`, |
| 40 | }, |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | func TestPythonLibraryPy2(t *testing.T) { |
| 45 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
| 46 | description: "py2 python_library", |
| 47 | moduleTypeUnderTest: "python_library", |
| 48 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 49 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
| 50 | blueprint: `python_library { |
| 51 | name: "foo", |
| 52 | srcs: ["a.py"], |
| 53 | version: { |
| 54 | py2: { |
| 55 | enabled: true, |
| 56 | }, |
| 57 | py3: { |
| 58 | enabled: false, |
| 59 | }, |
| 60 | }, |
| 61 | |
| 62 | bazel_module: { bp2build_available: true }, |
| 63 | } |
| 64 | `, |
| 65 | expectedBazelTargets: []string{`py_library( |
| 66 | name = "foo", |
| 67 | srcs = ["a.py"], |
| 68 | srcs_version = "PY2", |
| 69 | )`, |
| 70 | }, |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | func TestPythonLibraryPy3(t *testing.T) { |
| 75 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
| 76 | description: "py3 python_library", |
| 77 | moduleTypeUnderTest: "python_library", |
| 78 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 79 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
| 80 | blueprint: `python_library { |
| 81 | name: "foo", |
| 82 | srcs: ["a.py"], |
| 83 | version: { |
| 84 | py2: { |
| 85 | enabled: false, |
| 86 | }, |
| 87 | py3: { |
| 88 | enabled: true, |
| 89 | }, |
| 90 | }, |
| 91 | |
| 92 | bazel_module: { bp2build_available: true }, |
| 93 | } |
| 94 | `, |
| 95 | expectedBazelTargets: []string{ |
| 96 | `py_library( |
| 97 | name = "foo", |
| 98 | srcs = ["a.py"], |
| 99 | srcs_version = "PY3", |
| 100 | )`, |
| 101 | }, |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | func TestPythonLibraryPyBoth(t *testing.T) { |
| 106 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
| 107 | description: "py3 python_library", |
| 108 | moduleTypeUnderTest: "python_library", |
| 109 | moduleTypeUnderTestFactory: python.PythonLibraryFactory, |
| 110 | moduleTypeUnderTestBp2BuildMutator: python.PythonLibraryBp2Build, |
| 111 | blueprint: `python_library { |
| 112 | name: "foo", |
| 113 | srcs: ["a.py"], |
| 114 | version: { |
| 115 | py2: { |
| 116 | enabled: true, |
| 117 | }, |
| 118 | py3: { |
| 119 | enabled: true, |
| 120 | }, |
| 121 | }, |
| 122 | |
| 123 | bazel_module: { bp2build_available: true }, |
| 124 | } |
| 125 | `, |
| 126 | expectedBazelTargets: []string{ |
| 127 | // srcs_version is PY2ANDPY3 by default. |
| 128 | `py_library( |
| 129 | name = "foo", |
| 130 | srcs = ["a.py"], |
| 131 | )`, |
| 132 | }, |
| 133 | }) |
| 134 | } |