Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 4 | "testing" |
| 5 | |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 6 | "android/soong/python" |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 7 | ) |
| 8 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 9 | func TestPythonBinaryHostSimple(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ce0a07e | 2021-08-23 16:17:32 +0000 | [diff] [blame^] | 10 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 11 | description: "simple python_binary_host converts to a native py_binary", |
| 12 | moduleTypeUnderTest: "python_binary_host", |
| 13 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 14 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 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_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 23 | name: "foo", |
| 24 | main: "a.py", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 25 | srcs: ["**/*.py"], |
| 26 | exclude_srcs: ["b/e.py"], |
| 27 | data: ["files/data.txt",], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 28 | bazel_module: { bp2build_available: true }, |
| 29 | } |
| 30 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 31 | expectedBazelTargets: []string{`py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 32 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 33 | data = ["files/data.txt"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 34 | main = "a.py", |
| 35 | srcs = [ |
| 36 | "a.py", |
| 37 | "b/c.py", |
| 38 | "b/d.py", |
| 39 | ], |
| 40 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 41 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 42 | }) |
| 43 | } |
| 44 | |
| 45 | func TestPythonBinaryHostPy2(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ce0a07e | 2021-08-23 16:17:32 +0000 | [diff] [blame^] | 46 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 47 | description: "py2 python_binary_host", |
| 48 | moduleTypeUnderTest: "python_binary_host", |
| 49 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 50 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 51 | blueprint: `python_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 52 | name: "foo", |
| 53 | srcs: ["a.py"], |
| 54 | version: { |
| 55 | py2: { |
| 56 | enabled: true, |
| 57 | }, |
| 58 | py3: { |
| 59 | enabled: false, |
| 60 | }, |
| 61 | }, |
| 62 | |
| 63 | bazel_module: { bp2build_available: true }, |
| 64 | } |
| 65 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 66 | expectedBazelTargets: []string{`py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 67 | name = "foo", |
| 68 | python_version = "PY2", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 69 | srcs = ["a.py"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 70 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 71 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 72 | }) |
| 73 | } |
| 74 | |
| 75 | func TestPythonBinaryHostPy3(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ce0a07e | 2021-08-23 16:17:32 +0000 | [diff] [blame^] | 76 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 77 | description: "py3 python_binary_host", |
| 78 | moduleTypeUnderTest: "python_binary_host", |
| 79 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 80 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 81 | blueprint: `python_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 82 | name: "foo", |
| 83 | srcs: ["a.py"], |
| 84 | version: { |
| 85 | py2: { |
| 86 | enabled: false, |
| 87 | }, |
| 88 | py3: { |
| 89 | enabled: true, |
| 90 | }, |
| 91 | }, |
| 92 | |
| 93 | bazel_module: { bp2build_available: true }, |
| 94 | } |
| 95 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 96 | expectedBazelTargets: []string{ |
| 97 | // python_version is PY3 by default. |
| 98 | `py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 99 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 100 | srcs = ["a.py"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 101 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 102 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 103 | }) |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 104 | } |