Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Adding tests against abstract datum
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacBlanco committed Jul 1, 2016
1 parent a179814 commit 2ec5fdd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions scripts/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def check_for_key(self, key_name):
# A method to determine whether or not the schema object has the necessary fields.
@abstractmethod
def check(self):
pass
raise NotImplementedError('AbstractDatum: This method should have been implemented by a sublcass')

@abstractmethod
def generate(self, rand):
pass
raise NotImplementedError('AbstractDatum: This method should have been implemented by a sublcass')

class StringDatum(AbstractDatum):
values = []
Expand Down
25 changes: 24 additions & 1 deletion tests/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest, json, mock
import unittest, json, mock, random
from env import scripts
from mock import Mock
from scripts.generator import DataGenerator
from scripts.generator import AbstractDatum

class TestDataGenerator(unittest.TestCase):

Expand Down Expand Up @@ -85,6 +86,28 @@ def test_gen_check_values(self, mock1):
except KeyError as e:
assert('Missing key: values in field3' in str(e))

@mock.patch('scripts.config.get_conf_dir', return_value='res/')
def test_gen_abstract_datum(self, mock1):
try:
field = {}
field['fieldName'] = "ABC123"
field['type'] = "ABC123"
dat = AbstractDatum(field)
dat.check()
self.fail('Should raise not implemented error')
except NotImplementedError as e:
assert('AbstractDatum: This method should have been implemented by a sublcass' in str(e))

try:
field = {}
field['fieldName'] = "ABC123"
field['type'] = "ABC123"
dat = AbstractDatum(field)
dat.generate(random)
self.fail('Should raise not implemented error')
except NotImplementedError as e:
assert('AbstractDatum: This method should have been implemented by a sublcass' in str(e))




Expand Down

0 comments on commit 2ec5fdd

Please sign in to comment.