|
| 1 | +import pytest |
| 2 | +import rich.console |
| 3 | + |
| 4 | +from exasol.toolbox.nox._lint import Dependencies, report_illegal |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + "toml,expected", |
| 9 | + [ |
| 10 | + ( |
| 11 | + """ |
| 12 | + """, |
| 13 | + {} |
| 14 | + ), |
| 15 | + ( |
| 16 | + """ |
| 17 | +[tool.poetry.dependencies] |
| 18 | +python = "^3.8" |
| 19 | +example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} |
| 20 | +
|
| 21 | +[tool.poetry.dev.dependencies] |
| 22 | +nox = ">=2022.8.7" |
| 23 | +example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} |
| 24 | +
|
| 25 | +[tool.poetry.group.test.dependencies] |
| 26 | +sphinx = ">=5.3,<8" |
| 27 | +example-git = {git = "git@github.com:requests/requests.git"} |
| 28 | +
|
| 29 | +[tool.poetry.group.dev.dependencies] |
| 30 | +pytest = ">=7.2.2,<9" |
| 31 | +example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} |
| 32 | + """, |
| 33 | + { |
| 34 | + "tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"], |
| 35 | + "tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"], |
| 36 | + "tool.poetry.group.test.dependencies": ["example-git = {'git': 'git@github.com:requests/requests.git'}"], |
| 37 | + "tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"], |
| 38 | + } |
| 39 | + ), |
| 40 | + ( |
| 41 | + """ |
| 42 | +[tool.poetry.dev.dependencies] |
| 43 | +nox = ">=2022.8.7" |
| 44 | +example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} |
| 45 | +
|
| 46 | +[tool.poetry.group.test.dependencies] |
| 47 | +sphinx = ">=5.3,<8" |
| 48 | +example-git = {git = "git@github.com:requests/requests.git"} |
| 49 | +
|
| 50 | +[tool.poetry.group.dev.dependencies] |
| 51 | +pytest = ">=7.2.2,<9" |
| 52 | +example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} |
| 53 | + """, |
| 54 | + { |
| 55 | + "tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"], |
| 56 | + "tool.poetry.group.test.dependencies": ["example-git = {'git': 'git@github.com:requests/requests.git'}"], |
| 57 | + "tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"], |
| 58 | + } |
| 59 | + ), |
| 60 | + ( |
| 61 | + """ |
| 62 | +[tool.poetry.dependencies] |
| 63 | +python = "^3.8" |
| 64 | +example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} |
| 65 | +
|
| 66 | +[tool.poetry.group.test.dependencies] |
| 67 | +sphinx = ">=5.3,<8" |
| 68 | +example-git = {git = "git@github.com:requests/requests.git"} |
| 69 | +
|
| 70 | +[tool.poetry.group.dev.dependencies] |
| 71 | +pytest = ">=7.2.2,<9" |
| 72 | +example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} |
| 73 | + """, |
| 74 | + { |
| 75 | + "tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"], |
| 76 | + "tool.poetry.group.test.dependencies": ["example-git = {'git': 'git@github.com:requests/requests.git'}"], |
| 77 | + "tool.poetry.group.dev.dependencies": ["example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'}"], |
| 78 | + } |
| 79 | + ), |
| 80 | + ( |
| 81 | + """ |
| 82 | +[tool.poetry.dependencies] |
| 83 | +python = "^3.8" |
| 84 | +example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} |
| 85 | +
|
| 86 | +[tool.poetry.dev.dependencies] |
| 87 | +nox = ">=2022.8.7" |
| 88 | +example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} |
| 89 | + """, |
| 90 | + { |
| 91 | + "tool.poetry.dependencies": ["example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'}"], |
| 92 | + "tool.poetry.dev.dependencies": ["example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'}"], |
| 93 | + } |
| 94 | + ) |
| 95 | + ] |
| 96 | +) |
| 97 | +def test_dependency_check_parse(toml, expected): |
| 98 | + dependencies = dependencies = Dependencies.parse(toml) |
| 99 | + assert dependencies.illegal == expected |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.parametrize( |
| 103 | + "toml,expected", |
| 104 | + [ |
| 105 | + ( |
| 106 | + """ |
| 107 | +[tool.poetry.dependencies] |
| 108 | +python = "^3.8" |
| 109 | +example-url1 = {url = "https://example.com/my-package-0.1.0.tar.gz"} |
| 110 | +
|
| 111 | +[tool.poetry.dev.dependencies] |
| 112 | +nox = ">=2022.8.7" |
| 113 | +example-url2 = {url = "https://example.com/my-package-0.2.0.tar.gz"} |
| 114 | +
|
| 115 | +[tool.poetry.group.test.dependencies] |
| 116 | +sphinx = ">=5.3,<8" |
| 117 | +example-git = {git = "git@github.com:requests/requests.git"} |
| 118 | +
|
| 119 | +[tool.poetry.group.dev.dependencies] |
| 120 | +pytest = ">=7.2.2,<9" |
| 121 | +example-path1 = {path = "../my-package/dist/my-package-0.1.0.tar.gz"} |
| 122 | +example-path2 = {path = "../my-package/dist/my-package-0.2.0.tar.gz"} |
| 123 | + """, |
| 124 | + """5 illegal dependencies |
| 125 | +
|
| 126 | +[tool.poetry.dependencies] |
| 127 | +example-url1 = {'url': 'https://example.com/my-package-0.1.0.tar.gz'} |
| 128 | +
|
| 129 | +[tool.poetry.dev.dependencies] |
| 130 | +example-url2 = {'url': 'https://example.com/my-package-0.2.0.tar.gz'} |
| 131 | +
|
| 132 | +[tool.poetry.group.test.dependencies] |
| 133 | +example-git = {'git': 'git@github.com:requests/requests.git'} |
| 134 | +
|
| 135 | +[tool.poetry.group.dev.dependencies] |
| 136 | +example-path1 = {'path': '../my-package/dist/my-package-0.1.0.tar.gz'} |
| 137 | +example-path2 = {'path': '../my-package/dist/my-package-0.2.0.tar.gz'} |
| 138 | +
|
| 139 | +""" |
| 140 | + ), |
| 141 | + ] |
| 142 | +) |
| 143 | +def test_dependencies_check_report(toml, expected, capsys): |
| 144 | + console = rich.console.Console() |
| 145 | + dependencies = Dependencies.parse(toml) |
| 146 | + report_illegal(dependencies.illegal, console) |
| 147 | + assert capsys.readouterr().out == expected |
0 commit comments