Skip to content

Commit

Permalink
* Add script test-vb to Makefile
Browse files Browse the repository at this point in the history
*   Update `CONTRIBUTING.rst` to mention usage
*   Temporary fix for time string patterns that contain
    `-` or `+`, as PY 3.11+ can interpret this as time
    zone data.
  • Loading branch information
rnag committed Jan 29, 2024
1 parent 21aa6d0 commit b344431
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ Ready to contribute? Here's how to set up `dataclass-wizard` for local developme
tests, including testing other Python versions with tox::

$ make lint
$ make test
$ make test # or: see debug output with `make test-vb`
$ tox

To get flake8 and tox, just pip install them into your virtualenv.

To instead run pytest in verbose mode `-vvv` and also show
log output in terminal for debugging purposes, use::

$ make test-vb

6. Commit your changes and push your branch to GitHub::

$ git add .
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ lint: ## check style with flake8 and pylint
test: ## run unit tests quickly with the default Python
pytest -v --cov=dataclass_wizard --cov-report=term-missing tests/unit

test-vb: ## run unit tests (in verbose mode) with the default Python
pytest -vvv --log-cli-level=DEBUG --capture=tee-sys --cov=dataclass_wizard --cov-report=term-missing tests/unit

test-all: ## run tests on every Python version with tox
tox

Expand Down
22 changes: 21 additions & 1 deletion dataclass_wizard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,17 @@ def get_transform_func(self) -> Callable[[str], DT]:
body_lines.append('return dt.date()')
elif cls is time:
default_load_func = as_time
body_lines.append('return dt.time()')
# temp fix for Python 3.11+, since `time.fromisoformat` is updated
# to support more formats, such as "-" and "+" in strings.
if '-' in self.pattern or '+' in self.pattern:
body_lines = ['try:',
' return datetime.strptime(date_string, pattern).time()',
'except (ValueError, TypeError):',
' dt = default_load_func(date_string, cls, raise_=False)',
' if dt is not None:',
' return dt']
else:
body_lines.append('return dt.time()')
elif issubclass(cls, datetime):
default_load_func = as_datetime
locals_ns['datetime'] = cls
Expand All @@ -276,6 +286,16 @@ def get_transform_func(self) -> Callable[[str], DT]:
body_lines.append('return cls(dt.year, dt.month, dt.day)')
elif issubclass(cls, time):
default_load_func = as_time
# temp fix for Python 3.11+, since `time.fromisoformat` is updated
# to support more formats, such as "-" and "+" in strings.
if '-' in self.pattern or '+' in self.pattern:
body_lines = ['try:',
' dt = datetime.strptime(date_string, pattern).time()',
'except (ValueError, TypeError):',
' dt = default_load_func(date_string, cls, raise_=False)',
' if dt is not None:',
' return dt']

body_lines.append('return cls(dt.hour, dt.minute, dt.second, '
'dt.microsecond, fold=dt.fold)')
else:
Expand Down

0 comments on commit b344431

Please sign in to comment.