|
18 | 18 | import clkhash.cli
|
19 | 19 | from clkhash import randomnames
|
20 | 20 |
|
21 |
| -from tests import temporary_file, create_temp_file, SIMPLE_SCHEMA_PATH, RANDOMNAMES_SCHEMA_PATH |
| 21 | +from tests import * |
22 | 22 |
|
23 | 23 |
|
24 | 24 | class CLITestHelper(unittest.TestCase):
|
@@ -100,7 +100,9 @@ class BasicCLITests(unittest.TestCase):
|
100 | 100 | def test_list_commands(self):
|
101 | 101 | runner = CliRunner()
|
102 | 102 | result = runner.invoke(clkhash.cli.cli, [])
|
103 |
| - for expected_command in 'hash', 'upload', 'create', 'results', 'generate', 'benchmark': |
| 103 | + expected_commands = ['benchmark', 'create', 'create-project', 'generate', |
| 104 | + 'hash', 'upload', 'results', 'validate-schema'] |
| 105 | + for expected_command in expected_commands: |
104 | 106 | assert expected_command in result.output
|
105 | 107 |
|
106 | 108 | def test_version(self):
|
@@ -135,6 +137,43 @@ def test_bench(self):
|
135 | 137 | assert 'hashes in' in result.output
|
136 | 138 |
|
137 | 139 |
|
| 140 | +class TestSchemaValidationCommand(unittest.TestCase): |
| 141 | + |
| 142 | + @staticmethod |
| 143 | + def validate_schema(schema_path): |
| 144 | + runner = CliRunner() |
| 145 | + result = runner.invoke(clkhash.cli.cli, [ |
| 146 | + 'validate-schema', schema_path |
| 147 | + ]) |
| 148 | + return result |
| 149 | + |
| 150 | + def test_good_v1_schema(self): |
| 151 | + for schema_path in GOOD_SCHEMA_V1_PATH, SIMPLE_SCHEMA_PATH: |
| 152 | + result = self.validate_schema(schema_path) |
| 153 | + assert result.exit_code == 0 |
| 154 | + assert 'schema is valid' in result.output |
| 155 | + |
| 156 | + def test_bad_v1_schema(self): |
| 157 | + result = self.validate_schema(BAD_SCHEMA_V1_PATH) |
| 158 | + assert result.exit_code == -1 |
| 159 | + assert 'schema is not valid.' in result.output |
| 160 | + assert "'l' is a required property" in result.output |
| 161 | + |
| 162 | + |
| 163 | + def test_good_v2_schema(self): |
| 164 | + for schema_path in GOOD_SCHEMA_V2_PATH, RANDOMNAMES_SCHEMA_PATH: |
| 165 | + result = self.validate_schema(schema_path) |
| 166 | + assert result.exit_code == 0 |
| 167 | + assert 'schema is valid' in result.output |
| 168 | + |
| 169 | + def test_bad_v1_schema(self): |
| 170 | + result = self.validate_schema(BAD_SCHEMA_V2_PATH) |
| 171 | + assert result.exit_code == -1 |
| 172 | + assert 'schema is not valid.' in result.output |
| 173 | + assert "in schema['properties']['features']['items']" in result.output |
| 174 | + |
| 175 | + |
| 176 | + |
138 | 177 | @unittest.skipUnless("INCLUDE_CLI" in os.environ,
|
139 | 178 | "Set envvar INCLUDE_CLI to run. Disabled for jenkins")
|
140 | 179 | class TestHashCommand(unittest.TestCase):
|
|
0 commit comments