-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated project file * Added basic test * myjsonencoder integrated
- Loading branch information
Showing
3 changed files
with
59 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from decimal import Decimal | ||
from datetime import timezone, date, datetime, time, timedelta | ||
from pydicts import myjsonencoder | ||
d={} | ||
d["None"]=None | ||
d["Integer"]=12112 | ||
d["Float"]=12121.1212 | ||
d["Date"]=date.today() | ||
d["Datetime"]=datetime.now() | ||
d["Timedelta"]=timedelta(hours=4, days=2, minutes=12, seconds=12) | ||
d["Time"]=time(12, 12, 12, 123456) | ||
d["Datetime aware"]=d["Datetime"].replace(tzinfo=timezone.utc) | ||
d["Bytes"]=b"Byte array" | ||
d["Decimal"]=Decimal("12.12123414") | ||
|
||
def test_myjsonencoder(): | ||
json_string=myjsonencoder.MyJSONEncoder_dumps(d) | ||
json_=myjsonencoder.MyJSONEncoder_loads(json_string) | ||
assert json_["None"]==d["None"] | ||
assert json_["Integer"]==d["Integer"] | ||
assert json_["Float"]==d["Float"] | ||
assert json_["Date"]==d["Date"] | ||
assert json_["Datetime"]==d["Datetime"] | ||
assert json_["Datetime aware"]==d["Datetime aware"] | ||
assert json_["Bytes"]==d["Bytes"] | ||
assert json_["Decimal"]==d["Decimal"] | ||
# assert json_["Time"]==d["Time"] | ||
# assert json_["Timedelta"]==d["Timedelta"] | ||
|
||
def test_myjsonencoder_decimals_as_float(): | ||
json_string=myjsonencoder.MyJSONEncoderDecimalsAsFloat_dumps(d) | ||
json_=myjsonencoder.MyJSONEncoderDecimalsAsFloat_loads(json_string) | ||
assert json_["None"]==d["None"] | ||
assert json_["Integer"]==d["Integer"] | ||
assert json_["Float"]==d["Float"] | ||
assert json_["Date"]==d["Date"] | ||
assert json_["Datetime"]==d["Datetime"] | ||
assert json_["Datetime aware"]==d["Datetime aware"] | ||
assert json_["Bytes"]==d["Bytes"] | ||
assert json_["Decimal"]==float(d["Decimal"]) | ||
# assert json_["Time"]==d["Time"] | ||
# assert json_["Timedelta"]==d["Timedelta"] | ||
|
||
|
||
def test_myjsonencoder_decimals_as_string(): | ||
json_string=myjsonencoder.MyJSONEncoderDecimalsAsString_dumps(d) | ||
json_=myjsonencoder.MyJSONEncoderDecimalsAsString_loads(json_string) | ||
assert json_["None"]==d["None"] | ||
assert json_["Integer"]==d["Integer"] | ||
assert json_["Float"]==d["Float"] | ||
assert json_["Date"]==d["Date"] | ||
assert json_["Datetime"]==d["Datetime"] | ||
assert json_["Datetime aware"]==d["Datetime aware"] | ||
assert json_["Bytes"]==d["Bytes"] | ||
assert json_["Decimal"]==str(d["Decimal"]) | ||
# assert json_["Time"]==d["Time"] | ||
# assert json_["Timedelta"]==d["Timedelta"] |