|
15 | 15 | import os
|
16 | 16 | from pathlib import Path
|
17 | 17 |
|
| 18 | +import pytest |
| 19 | + |
18 | 20 | from synthtool import gcp
|
| 21 | +from synthtool.sources import templates |
| 22 | + |
| 23 | + |
| 24 | +PYTHON_LIBRARY = Path(__file__).parent.parent / "synthtool/gcp/templates/python_library" |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.parametrize( |
| 28 | + ["template_kwargs", "expected_text"], |
| 29 | + [ |
| 30 | + ({}, ["import nox", 'session.install("-e", ".")']), |
| 31 | + ( |
| 32 | + {"unit_test_local_dependencies": ["../testutils", "../unitutils"]}, |
| 33 | + [ |
| 34 | + 'session.install("-e", "../testutils")', |
| 35 | + 'session.install("-e", "../unitutils")', |
| 36 | + ], |
| 37 | + ), |
| 38 | + ( |
| 39 | + {"system_test_local_dependencies": ["../testutils", "../sysutils"]}, |
| 40 | + [ |
| 41 | + 'session.install("-e", "../testutils")', |
| 42 | + 'session.install("-e", "../sysutils")', |
| 43 | + ], |
| 44 | + ), |
| 45 | + ( |
| 46 | + {"unit_test_extras": ["abc", "def"]}, |
| 47 | + ['session.install("-e", ".[abc,def]")'], |
| 48 | + ), |
| 49 | + ( |
| 50 | + {"system_test_extras": ["abc", "def"]}, |
| 51 | + ['session.install("-e", ".[abc,def]")'], |
| 52 | + ), |
| 53 | + ( |
| 54 | + {"unit_test_extras_by_python": {"3.8": ["abc", "def"]}}, |
| 55 | + [ |
| 56 | + 'if session.python == "3.8":\n extras = "[abc,def]"', |
| 57 | + 'else:\n extras = ""', |
| 58 | + 'session.install("-e", f".{extras}")', |
| 59 | + ], |
| 60 | + ), |
| 61 | + ( |
| 62 | + {"system_test_extras_by_python": {"3.8": ["abc", "def"]}}, |
| 63 | + [ |
| 64 | + 'if session.python == "3.8":\n extras = "[abc,def]"', |
| 65 | + 'else:\n extras = ""', |
| 66 | + 'session.install("-e", f".{extras}")', |
| 67 | + ], |
| 68 | + ), |
| 69 | + ( |
| 70 | + { |
| 71 | + "unit_test_extras": ["tuv", "wxyz"], |
| 72 | + "unit_test_extras_by_python": {"3.8": ["abc", "def"]}, |
| 73 | + }, |
| 74 | + [ |
| 75 | + 'if session.python == "3.8":\n extras = "[abc,def]"', |
| 76 | + 'else:\n extras = "[tuv,wxyz]"', |
| 77 | + 'session.install("-e", f".{extras}")', |
| 78 | + ], |
| 79 | + ), |
| 80 | + ( |
| 81 | + { |
| 82 | + "system_test_extras": ["tuv", "wxyz"], |
| 83 | + "system_test_extras_by_python": {"3.8": ["abc", "def"]}, |
| 84 | + }, |
| 85 | + [ |
| 86 | + 'if session.python == "3.8":\n extras = "[abc,def]"', |
| 87 | + 'else:\n extras = "[tuv,wxyz]"', |
| 88 | + 'session.install("-e", f".{extras}")', |
| 89 | + ], |
| 90 | + ), |
| 91 | + ], |
| 92 | +) |
| 93 | +def test_library_noxfile(template_kwargs, expected_text): |
| 94 | + t = templates.Templates(PYTHON_LIBRARY) |
| 95 | + result = t.render("noxfile.py.j2", **template_kwargs,).read_text() |
| 96 | + # Validate Python syntax. |
| 97 | + result_code = compile(result, "noxfile.py", "exec") |
| 98 | + assert result_code is not None |
| 99 | + for expected in expected_text: |
| 100 | + assert expected in result |
19 | 101 |
|
20 | 102 |
|
21 | 103 | def test_python_library():
|
|
0 commit comments