Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hykin committed Feb 13, 2024
1 parent cb9219f commit 742e62b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
author_email=package_info["author_email"],
license=package_info["license"],
packages=[package_info["name"]],
# package_data={
# package_info["name"]: ['__dependencies__/**/*'],
# },
install_requires=[
# examples:
# 'aiohttp >= 3.7.4',
Expand Down
15 changes: 15 additions & 0 deletions tests/4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import json
import json_fix

class Test(dict):
def __json__(self):
return 99

with open("tests/test4.json", "w") as f:
json.dump([Test()], f)

# print(f'''test4, pt3, should print and throw error''')
# print(json.dumps(Test()))

# print(f'''test4, pt4, should print and throw error''')
# print(json.dumps([Test()]))
16 changes: 16 additions & 0 deletions tests/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
from json import JSONEncoder
from os.path import join
import json_fix

# same file, or different file
class YOUR_CLASS(dict):
def __json__(self):
# YOUR CUSTOM CODE HERE
# you probably just want to do:
# return self.__dict__
return "a built-in object that is natually json-able"

result = [ 1, 2, YOUR_CLASS() ]
with open('tests/test5.json', 'w') as outfile:
json.dump(result, outfile)
1 change: 1 addition & 0 deletions tests/test4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{}]
1 change: 1 addition & 0 deletions tests/test4_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions tests/test5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2, {}]

0 comments on commit 742e62b

Please sign in to comment.