Skip to content

Commit

Permalink
Info: Add example_values field.
Browse files Browse the repository at this point in the history
Adds a class attribute named example_values illustrating
sample information values that are allowed to be stored
inside the Info class.

Closes #125
  • Loading branch information
satwikkansal committed Jun 26, 2017
1 parent 1d16901 commit a348113
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion coala_quickstart/info_extraction/Info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@


class Info:
description = 'Some information'
description = 'Some Description.'

# type signature for the information value.
value_type = (object,)

# Some example values for reference that also match the value_type.
example_values = []

def __init__(self,
source,
value,
Expand Down
6 changes: 5 additions & 1 deletion tests/info_extraction/InfoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def find_information(self, fname, parsed_file):
class InfoA(Info):
description = 'Information A'
value_type = (str, int)
example_values = ['coala', 420]

class InfoB(Info):
description = "Info class without value_type"
example_values = [["literally", "anything"]]

self.info_a = InfoA(
'source_file',
Expand All @@ -43,7 +45,8 @@ def test_main(self):
self.assertEqual(self.base_info.name, 'Info')
self.assertEqual(self.base_info.value, 'base_info_value')
self.assertEqual(self.base_info.source, 'source_file')
self.assertEqual(self.base_info.description, 'Some information')
self.assertEqual(self.base_info.description, 'Some Description.')
self.assertEqual(len(self.base_info.example_values), 0)
self.assertIsInstance(self.base_info.extractor, InfoExtractor)

def test_derived_instances(self):
Expand All @@ -52,6 +55,7 @@ def test_derived_instances(self):
self.assertEqual(self.info_a.source, 'source_file')
self.assertEqual(self.info_a.extra_param, 'extra_param_value')
self.assertEqual(self.info_a.description, 'Information A')
self.assertEqual(self.info_a.example_values, ['coala', 420])

def test_value_type(self):
with self.assertRaisesRegexp(
Expand Down

0 comments on commit a348113

Please sign in to comment.