Skip to content

Commit 0259e01

Browse files
committed
Add cli schema validation tests
1 parent a480f65 commit 0259e01

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

tests/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@
33
import tempfile
44
import clkhash
55

6-
SIMPLE_SCHEMA_PATH = os.path.join(
6+
TESTDATA = os.path.join(
77
os.path.dirname(__file__),
8-
'testdata',
9-
'simple-schema.json'
10-
)
11-
SAMPLE_DATA_SCHEMA_PATH = os.path.join(
12-
os.path.dirname(__file__),
13-
'testdata',
14-
'dirty-data-schema.json'
8+
'testdata'
159
)
1610

11+
SIMPLE_SCHEMA_PATH = os.path.join(TESTDATA, 'simple-schema.json')
12+
13+
SAMPLE_DATA_SCHEMA_PATH = os.path.join(TESTDATA, 'dirty-data-schema.json')
14+
15+
GOOD_SCHEMA_V1_PATH = os.path.join(TESTDATA, 'good-schema-v1.json')
16+
GOOD_SCHEMA_V2_PATH = os.path.join(TESTDATA, 'good-schema-v2.json')
17+
BAD_SCHEMA_V1_PATH = os.path.join(TESTDATA, 'bad-schema-v1.json')
18+
BAD_SCHEMA_V2_PATH = os.path.join(TESTDATA, 'bad-schema-v2.json')
19+
1720
RANDOMNAMES_SCHEMA_PATH = os.path.join(
18-
os.path.dirname(clkhash.__file__),
19-
'data',
20-
'randomnames-schema.json'
21+
TESTDATA,
22+
'randomnames-schema-v2.json'
2123
)
2224

23-
SAMPLE_DATA_PATH_1 = os.path.join(os.path.dirname(__file__), 'testdata', 'dirty_1000_50_1.csv')
24-
SAMPLE_DATA_PATH_2 = os.path.join(os.path.dirname(__file__), 'testdata', 'dirty_1000_50_2.csv')
25+
SAMPLE_DATA_PATH_1 = os.path.join(TESTDATA, 'dirty_1000_50_1.csv')
26+
SAMPLE_DATA_PATH_2 = os.path.join(TESTDATA, 'dirty_1000_50_2.csv')
2527

2628

2729
class temporary_file(object):

tests/test_cli.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import clkhash.cli
1919
from clkhash import randomnames
2020

21-
from tests import temporary_file, create_temp_file, SIMPLE_SCHEMA_PATH, RANDOMNAMES_SCHEMA_PATH
21+
from tests import *
2222

2323

2424
class CLITestHelper(unittest.TestCase):
@@ -100,7 +100,9 @@ class BasicCLITests(unittest.TestCase):
100100
def test_list_commands(self):
101101
runner = CliRunner()
102102
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:
104106
assert expected_command in result.output
105107

106108
def test_version(self):
@@ -135,6 +137,43 @@ def test_bench(self):
135137
assert 'hashes in' in result.output
136138

137139

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+
138177
@unittest.skipUnless("INCLUDE_CLI" in os.environ,
139178
"Set envvar INCLUDE_CLI to run. Disabled for jenkins")
140179
class TestHashCommand(unittest.TestCase):

0 commit comments

Comments
 (0)