Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1758 : fix recursive hasattr call #7

Merged
merged 12 commits into from
Apr 10, 2022
10 changes: 5 additions & 5 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['2.x', '3.x']
python-version: [2.7, 3.7]
env:
MYGEOTAB_DATABASE: ${{ secrets.MYGEOTAB_DATABASE }}
MYGEOTAB_USERNAME: ${{ secrets.MYGEOTAB_USERNAME }}
Expand All @@ -25,9 +25,9 @@ jobs:
MYGEOTAB_USERNAME_ASYNC: ${{ secrets.MYGEOTAB_USERNAME_ASYNC }}
MYGEOTAB_PASSWORD_ASYNC: ${{ secrets.MYGEOTAB_PASSWORD_ASYNC }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -51,12 +51,12 @@ jobs:
pipenv run py.test --ignore-glob='*_async.py' --junitxml output/python${{ matrix.python-version }}-test-results.xml --benchmark-min-rounds=3 --benchmark-storage=file://output/ --benchmark-autosave tests/
- name: Upload coverage to Codecov
if: matrix.python-version >= 3.10
uses: codecov/codecov-action@v1.0.3
uses: codecov/codecov-action@v2
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./output/coverage.xml
- name: Archive code coverage results
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: output
path: output
6 changes: 5 additions & 1 deletion mygeotab/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def object_serializer(obj):

:param obj: The object.
"""
return dates.format_iso_datetime(obj) if hasattr(obj, "isoformat") else obj
if hasattr(obj, 'isoformat'):
return dates.format_iso_datetime(obj)
else:
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(obj)


def object_deserializer(obj):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from datetime import date, datetime

import pytest
import pytz

from mygeotab import serializers, dates
Expand Down Expand Up @@ -42,6 +43,10 @@ def test_only_date(self):
data_str = json_serialize(data)
assert data_str == expected_str

def test_unparsable_data_throws(self):
with pytest.raises(TypeError):
json_serialize({''})


class TestDeserialization:
def test_top_level_datetime(self):
Expand Down