|
| 1 | +import json |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pathlib import Path |
| 5 | +import sqlite3 |
| 6 | + |
| 7 | +from exasol.toolbox.nox import _gh |
| 8 | + |
| 9 | +@pytest.mark.parametrize( |
| 10 | + "files,requested_files,expected", |
| 11 | + [ |
| 12 | + ( |
| 13 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 14 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 15 | + [] |
| 16 | + ), ( |
| 17 | + [".lint.txt", ".security.json", ".coverage"], |
| 18 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 19 | + [".lint.json"] |
| 20 | + ), ( |
| 21 | + [".lint.json", ".security.json", ".coverage"], |
| 22 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 23 | + [".lint.txt"] |
| 24 | + ), ( |
| 25 | + [".lint.json", ".lint.txt", ".coverage"], |
| 26 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 27 | + [".security.json"] |
| 28 | + ), ( |
| 29 | + [".lint.json", ".lint.txt", ".security.json"], |
| 30 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 31 | + [".coverage"] |
| 32 | + ), ( |
| 33 | + [], |
| 34 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"], |
| 35 | + [".lint.json", ".lint.txt", ".security.json", ".coverage"] |
| 36 | + ), |
| 37 | + ] |
| 38 | +) |
| 39 | +def test_check_lint_files(files, requested_files, expected, tmp_path): |
| 40 | + path = Path(tmp_path) |
| 41 | + for file in files: |
| 42 | + Path(path, file).touch() |
| 43 | + |
| 44 | + actual = _gh.files_not_available(requested_files, path) |
| 45 | + assert actual == expected |
| 46 | + |
| 47 | + |
| 48 | +@pytest.mark.parametrize( |
| 49 | + "attributes,expected", |
| 50 | + [ |
| 51 | + ( |
| 52 | + ["type", "module", "obj", "line", "column", "endLine", |
| 53 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 54 | + "" |
| 55 | + ), ( |
| 56 | + ["module", "obj", "line", "column", "endLine", |
| 57 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 58 | + "incompatible format" |
| 59 | + ), ( |
| 60 | + ["type", "obj", "line", "column", "endLine", |
| 61 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 62 | + "incompatible format" |
| 63 | + ), ( |
| 64 | + ["type", "module", "line", "column", "endLine", |
| 65 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 66 | + "incompatible format" |
| 67 | + ), ( |
| 68 | + ["type", "module", "obj", "column", "endLine", |
| 69 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 70 | + "incompatible format" |
| 71 | + ), ( |
| 72 | + ["type", "module", "obj", "line", "endLine", |
| 73 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 74 | + "incompatible format" |
| 75 | + ), ( |
| 76 | + ["type", "module", "obj", "line", "column", |
| 77 | + "endColumn", "path", "symbol", "message", "message-id"], |
| 78 | + "incompatible format" |
| 79 | + ), ( |
| 80 | + ["type", "module", "obj", "line", "column", "endLine", |
| 81 | + "path", "symbol", "message", "message-id"], |
| 82 | + "incompatible format" |
| 83 | + ), ( |
| 84 | + ["type", "module", "obj", "line", "column", "endLine", |
| 85 | + "endColumn", "symbol", "message", "message-id"], |
| 86 | + "incompatible format" |
| 87 | + ), ( |
| 88 | + ["type", "module", "obj", "line", "column", "endLine", |
| 89 | + "endColumn", "path", "message", "message-id"], |
| 90 | + "incompatible format" |
| 91 | + ), ( |
| 92 | + ["type", "module", "obj", "line", "column", "endLine", |
| 93 | + "endColumn", "path", "symbol", "message-id"], |
| 94 | + "incompatible format" |
| 95 | + ), ( |
| 96 | + ["type", "module", "obj", "line", "column", "endLine", |
| 97 | + "endColumn", "path", "symbol", "message"], |
| 98 | + "incompatible format" |
| 99 | + ), |
| 100 | + ] |
| 101 | +) |
| 102 | +def test_check_lint_json(attributes, expected, tmp_path): |
| 103 | + path = Path(tmp_path, ".lint.json") |
| 104 | + path.touch() |
| 105 | + attributes_dict = {} |
| 106 | + for attribute in attributes: |
| 107 | + attributes_dict[attribute] = None |
| 108 | + with path.open("w") as file: |
| 109 | + json.dump([attributes_dict], file) |
| 110 | + actual = _gh.check_lint_json(path.parent) |
| 111 | + assert actual == expected |
| 112 | + |
| 113 | + |
| 114 | +@pytest.mark.parametrize( |
| 115 | + "attributes,expected", |
| 116 | + [ |
| 117 | + (['errors', 'generated_at', 'metrics', 'results'], ""), |
| 118 | + (["generated_at", "metrics", "results"], "incompatible format"), |
| 119 | + (["errors", "metrics", "results"], "incompatible format"), |
| 120 | + (["errors", "generated_at", "results"], "incompatible format"), |
| 121 | + (["errors", "generated_at", "metrics"], "incompatible format"), |
| 122 | + ] |
| 123 | +) |
| 124 | +def test_check_lint_json(attributes, expected, tmp_path): |
| 125 | + path = Path(tmp_path, ".security.json") |
| 126 | + path.touch() |
| 127 | + attributes_dict = {} |
| 128 | + for attribute in attributes: |
| 129 | + attributes_dict[attribute] = None |
| 130 | + with path.open("w") as file: |
| 131 | + json.dump(attributes_dict, file) |
| 132 | + actual = _gh.check_security_json(path.parent) |
| 133 | + assert actual == expected |
| 134 | + |
| 135 | + |
| 136 | +@pytest.mark.parametrize( |
| 137 | + "tables, expected", |
| 138 | + [ |
| 139 | + (["coverage_schema", "meta", "file", "line_bits"], ""), |
| 140 | + (["meta", "file", "line_bits"], "not existing tables: ['coverage_schema']"), |
| 141 | + (["coverage_schema", "file", "line_bits"], "not existing tables: ['meta']"), |
| 142 | + (["coverage_schema", "meta", "line_bits"], "not existing tables: ['file']"), |
| 143 | + (["coverage_schema", "meta", "file", ], "not existing tables: ['line_bits']"), |
| 144 | + ] |
| 145 | +) |
| 146 | +def test_check_coverage(tables, expected, tmp_path): |
| 147 | + path = Path(tmp_path, ".coverage") |
| 148 | + connection = sqlite3.connect(path) |
| 149 | + cursor = connection.cursor() |
| 150 | + for table in tables: |
| 151 | + cursor.execute(f"CREATE TABLE IF NOT EXISTS {table} (test INTEGER)") |
| 152 | + actual = _gh.check_coverage(path.parent) |
| 153 | + assert actual == expected |
0 commit comments