Skip to content

Commit 46ca200

Browse files
committed
more tests cleanup
1 parent be9988e commit 46ca200

File tree

2 files changed

+39
-49
lines changed

2 files changed

+39
-49
lines changed

tests/test_end_to_end.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import json
22
import unittest
3-
import subprocess
3+
from subprocess import check_output
44
import tempfile
5+
import fixtures
56

67

7-
class BinSchemaInferer(unittest.TestCase):
8+
class SkinferScriptTest(unittest.TestCase):
9+
script = 'skinfer'
810
def test_end_to_end_simple_run(self):
911
# given:
1012
_, filename = tempfile.mkstemp()
@@ -25,6 +27,40 @@ def test_end_to_end_simple_run(self):
2527
}
2628

2729
# when:
28-
output = subprocess.check_output(['schema_inferer', filename])
30+
output = check_output([self.script, filename])
2931
# then:
3032
self.assertEqual(expected, json.loads(output))
33+
34+
def test_run_with_json_samples_in_separate_files(self):
35+
# given:
36+
sample1 = fixtures.get_sample_path('minimal-1.json')
37+
sample2 = fixtures.get_sample_path('sample2-yelp.json')
38+
# when:
39+
output = check_output([self.script, sample1, sample2])
40+
# then:
41+
data = json.loads(output)
42+
self.assertIsNotNone(data)
43+
self.assertIn('required', data)
44+
self.assertIn('properties', data)
45+
46+
def test_run_with_jsonlines_samples(self):
47+
# given:
48+
infile = fixtures.get_sample_path('jsonlines.jsonl')
49+
# when:
50+
output = check_output([self.script, '--jsonlines', infile])
51+
# then:
52+
data = json.loads(output)
53+
self.assertIsNotNone(data)
54+
self.assertIn('required', data)
55+
self.assertIn('properties', data)
56+
57+
def test_run_with_jsonlines_samples_omitting_option(self):
58+
# given:
59+
infile = fixtures.get_sample_path('jsonlines.jsonl')
60+
# when:
61+
output = check_output([self.script, infile])
62+
# then:
63+
data = json.loads(output)
64+
self.assertIsNotNone(data)
65+
self.assertIn('required', data)
66+
self.assertIn('properties', data)

tests/test_schema_inferer.py

-46
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
from __future__ import absolute_import, print_function
55
import unittest
6-
import json
76
from tests import fixtures
87
from skinfer import schema_inferer
9-
from subprocess import check_output
108

119

1210
class TestJsonSchemaInferer(unittest.TestCase):
@@ -37,47 +35,3 @@ def test_load_jsonlines_samples(self):
3735

3836
# then:
3937
self.assertEquals(3, len(samples))
40-
41-
42-
class TestCasePython26Shim(unittest.TestCase):
43-
def assertIsNotNone(self, value):
44-
self.assertFalse(value is None, "%r is not None" % value)
45-
46-
def assertIn(self, value, seq):
47-
self.assertTrue(value in seq, "%r is not in %r" % (value, seq))
48-
49-
50-
class TestSchemaInfererScriptTest(TestCasePython26Shim):
51-
def test_run_with_json_samples_in_separate_files(self):
52-
# given:
53-
sample1 = fixtures.get_sample_path('minimal-1.json')
54-
sample2 = fixtures.get_sample_path('sample2-yelp.json')
55-
# when:
56-
output = check_output(['bin/schema_inferer', sample1, sample2])
57-
# then:
58-
data = json.loads(output)
59-
self.assertIsNotNone(data)
60-
self.assertIn('required', data)
61-
self.assertIn('properties', data)
62-
63-
def test_run_with_jsonlines_samples(self):
64-
# given:
65-
infile = fixtures.get_sample_path('jsonlines.jsonl')
66-
# when:
67-
output = check_output(['bin/schema_inferer', '--jsonlines', infile])
68-
# then:
69-
data = json.loads(output)
70-
self.assertIsNotNone(data)
71-
self.assertIn('required', data)
72-
self.assertIn('properties', data)
73-
74-
def test_run_with_jsonlines_samples_omitting_option(self):
75-
# given:
76-
infile = fixtures.get_sample_path('jsonlines.jsonl')
77-
# when:
78-
output = check_output(['bin/schema_inferer', infile])
79-
# then:
80-
data = json.loads(output)
81-
self.assertIsNotNone(data)
82-
self.assertIn('required', data)
83-
self.assertIn('properties', data)

0 commit comments

Comments
 (0)