Skip to content

Commit

Permalink
Ignore empty strings in KEYVALUEJSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
kbairak committed Apr 19, 2016
1 parent 141d0af commit 32bd6de
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openformats/formats/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def _extract(self, parsed, nest=None):
self.existing_keys.add(key)

if isinstance(value, (str, unicode)):
if not value.strip():
continue
openstring = OpenString(key, value,
order=next(self._order))
self.transcriber.copy_until(value_position)
Expand All @@ -71,6 +73,8 @@ def _extract(self, parsed, nest=None):
else:
key = u"{}..{}..".format(nest, index)
if isinstance(item, (str, unicode)):
if not item.strip():
continue
openstring = OpenString(key, item, order=next(self._order))
self.transcriber.copy_until(item_position)
self.transcriber.add(openstring.template_replacement)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class JsonTestCase(CommonFormatTestMixin, unittest.TestCase):
HANDLER_CLASS = JsonHandler
TESTFILE_BASE = "openformats/tests/formats/json/files"
TESTFILE_BASE = "openformats/tests/formats/beta_keyvaluejson/files"

def setUp(self):
super(JsonTestCase, self).setUp()
Expand All @@ -32,6 +32,12 @@ def test_simple(self):
self.random_openstring.__dict__)
self.assertEquals(compiled, '{"a": "%s"}' % self.random_string)

def test_empty_string_ignored(self):
template, stringset = self.handler.parse(
'{"not_empty": "hello there", "empty": ""}'
)
self.assertEquals(len(stringset), 1)

def test_root_object_is_list(self):
source = '["%s"]' % self.random_string
random_openstring = OpenString('..0..', self.random_string, order=0)
Expand Down

0 comments on commit 32bd6de

Please sign in to comment.