Skip to content

Commit

Permalink
Add new test and fix for case where document is not provided to app
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVinyard committed Jan 24, 2019
1 parent 7d74249 commit f0b69ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions zounds/ui/featureparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def result(self):
return self.doc, feature

def visit_Expr(self, node):
if self.document is None:
raise ValueError()

children = list(ast.iter_child_nodes(node))
if len(children) != 1:
raise ValueError()
Expand Down
17 changes: 12 additions & 5 deletions zounds/ui/test_featureparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from zounds.timeseries import SR44100, Seconds


class SomethingElse(object):
def __init__(self, fft):
super(SomethingElse, self).__init__()
self.fft = fft

class FeatureParserTests(unittest2.TestCase):

def setUp(self):
Expand All @@ -19,11 +24,6 @@ class Document(stft(store_fft=True)):
_id = Document.process(meta=audio.encode())
doc = Document(_id)

class SomethingElse(object):
def __init__(self, fft):
super(SomethingElse, self).__init__()
self.fft = fft

non_doc = SomethingElse(11)

parser = FeatureParser(Document, locals())
Expand Down Expand Up @@ -61,3 +61,10 @@ def test_can_ignore_non_document_with_matching_attribute_name(self):
parsed_doc, feature = self.parser.parse_feature('non_doc.fft')
self.assertIsNone(parsed_doc)
self.assertIsNone(feature)

def test_can_ignore_when_document_is_not_supplied(self):
non_doc = SomethingElse(11)
parser = FeatureParser(None, locals())
parsed_doc, feature = parser.parse_feature('non_doc.fft')
self.assertIsNone(parsed_doc)
self.assertIsNone(feature)

0 comments on commit f0b69ef

Please sign in to comment.