Skip to content

Commit

Permalink
for the 100%-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmaslanka committed Jun 29, 2021
1 parent 4715553 commit d11f7d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
[metadata]
version = 2.4a4
version = 2.4a5
name = minijson
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
Expand Down
12 changes: 12 additions & 0 deletions tests/test_minijson.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ def assertLoadingIsDecodingError(self, b: bytes):
def assertSameAfterDumpsAndLoads(self, c):
self.assertEqual(loads(dumps(c)), c)

def test_default_returns_nonjsonable(self):
"""Assert that if transform returns a non-JSONable value, EncodingError is raised"""
def transform(c):
return c

self.assertRaises(EncodingError, lambda: dumps(2+3j, transform))

def test_default(self):
"""Assert the default argument works"""
def transform(c):
return c.real, c.imag

dumps(2 + 3j, transform)
dumps({'test': 2 + 3j}, transform)

def test_subclasses_of_dicts(self):
"""Assert that you can correctly serialize subclasses of dict"""
class Subclass(dict):
pass

Expand All @@ -33,6 +42,7 @@ class Subclass(dict):
self.assertEquals(loads(b), {1: 2, 3: 4})

def test_subclasses_of_lists(self):
"""Assert that you can correctly serialize subclasses of list"""
class Subclass(list):
pass

Expand All @@ -41,6 +51,7 @@ class Subclass(list):
self.assertEquals(loads(b), [1, 2, 3])

def test_subclasses_of_tuples(self):
"""Assert that you can correctly serialize subclasses of tuple"""
class Subclass(tuple):
pass

Expand All @@ -49,6 +60,7 @@ class Subclass(tuple):
self.assertEquals(loads(b), [1, 2, 3])

def test_malformed(self):
"""Test unserializing malformed strings yields DecodingError"""
self.assertRaises(EncodingError, lambda: dumps(2 + 3j))
self.assertLoadingIsDecodingError(b'\x00\x02a')
self.assertLoadingIsDecodingError(b'\x00\x02a')
Expand Down

0 comments on commit d11f7d6

Please sign in to comment.