Skip to content

Commit

Permalink
bugfix (#8)
Browse files Browse the repository at this point in the history
* add base64 converter

* bugfix

* Revert "add base64 converter"

This reverts commit 3e88f0b.
  • Loading branch information
PythonFZ authored Jan 19, 2022
1 parent 553e366 commit b235189
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="znjson",
version="0.0.4",
version="0.0.5",
author="zincwarecode",
author_email="[email protected]",
description="A Python Package to Encode/Decode some common file formats to json",
Expand Down
30 changes: 20 additions & 10 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@

import znjson

znjson.register(znjson.PathlibConverter)


@pytest.fixture
def simple_dict():
return {"a": 10, "b": 20}


@pytest.fixture()
def pathlib_path():
return pathlib.Path("test_path.txt")


@pytest.fixture()
def serialized_pathlib_path():
return '{"_type": "pathlib.Path", "value": "test_path.txt"}'


def test_encoder_serializable(simple_dict):
_ = json.dumps(simple_dict, cls=znjson.ZnEncoder)

Expand All @@ -29,3 +21,21 @@ def test_decoder_serializable(simple_dict):
data_str = json.dumps(simple_dict, cls=znjson.ZnEncoder)

assert simple_dict == json.loads(data_str, cls=znjson.ZnDecoder)


def test_decode_pathlib():
data_str = '{"_type": "pathlib.Path", "value": "test_path.txt"}'

assert json.loads(data_str, cls=znjson.ZnDecoder) == pathlib.Path("test_path.txt")


def test_decode_pathlib_wo__type():
data_str = '{"value": "test_path.txt"}'

assert json.loads(data_str, cls=znjson.ZnDecoder) == {"value": "test_path.txt"}


def test_decode_pathlib_wo_value():
data_str = '{"_type": "pathlib.Path"}'

assert json.loads(data_str, cls=znjson.ZnDecoder) == {"_type": "pathlib.Path"}
2 changes: 1 addition & 1 deletion znjson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

__all__ = ["ConverterBase", "ZnDecoder", "ZnEncoder", "register", "config"]

__version__ = "0.0.4"
__version__ = "0.0.5"
2 changes: 2 additions & 0 deletions znjson/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def __init__(self):

def object_hook(self, obj):
try:
# must have "_type" and "value" keys
instance = obj["_type"]
_ = obj["value"]
except KeyError:
return obj
config.sort()
Expand Down

0 comments on commit b235189

Please sign in to comment.