Skip to content

Commit

Permalink
Made deserialization error messages more helpful; switched to GitHub …
Browse files Browse the repository at this point in the history
…workflows (#27)

* Add github workflow

* Still a problem?

* Was it the now?

* Whyyyy

* Is this the problem?

* I hate you

* Made deserialization messages more informative

* Oops

* Removed appveyor file
  • Loading branch information
sdrobert committed Jul 25, 2023
1 parent c87d878 commit bddf658
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 66 deletions.
56 changes: 0 additions & 56 deletions .appveyor.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# adapted from https://github.com/tox-dev/tox-gh

name: tox
on:
push:
branches-ignore:
- docs
pull_request:
schedule:
# run every monday @ 8am
- cron: "0 8 * * 1"

concurrency:
group: tox-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Python ${{ matrix.py }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
py:
- "3.11"
- "3.7"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
- name: Install tox
run: python -m pip install tox-gh>=1.2
- name: Setup test suite
run: tox -vv --notest
- name: Run test suite
run: tox --skip-pkg-install
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.4.1

- Made deserialization error messages more informative
- Switched to GitHub workflows

## v0.4.0

- Added extras.
Expand Down
2 changes: 1 addition & 1 deletion src/pydrobert/param/_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def __call__(
**self.class_.param.deserialize_parameters(value, subset, mode)
)
except Exception as e:
msg = f": {e.msg}" if hasattr(e, "msg") else ""
msg = f": {e.args[0]}" if hasattr(e, "args") else ""
raise argparse.ArgumentError(
self,
f"error deserializing '{name}' as '{self.class_.__name__}' with "
Expand Down
31 changes: 23 additions & 8 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import sys

from datetime import datetime
from datetime import datetime, timedelta

import pytest
import param
Expand Down Expand Up @@ -130,7 +130,10 @@ class P(param.Parameterized):
except TypeError:
data_frame = param.DataFrame(pd.DataFrame({"A": 1.0, "B": np.arange(5)}))
date = param.Date(datetime.now(), allow_None=True)
date_range = param.DateRange((datetime.min, datetime.max), allow_None=True)
date_range = param.DateRange(
(datetime.now() - timedelta(days=1), datetime.now() + timedelta(days=1)),
allow_None=True,
)
dict_ = param.Dict({"foo": "bar"}, allow_None=True, doc="dict means dictionary")
dynamic = param.Dynamic(default=_default_action, allow_None=True)
file_selector = param.FileSelector(
Expand Down Expand Up @@ -189,14 +192,14 @@ class P(param.Parameterized):
assert p_a.pprint() == p_b.pprint()


def test_deserialization_action(temp_dir, mode):
def test_deserialization_action(temp_dir, mode, capsys):
class Foo(param.Parameterized):
a = param.Integer(1)
b = param.Boolean(False)
c = param.Magnitude(None)
my_int = param.Integer(1)
my_bool = param.Boolean(False)
my_mag = param.Magnitude(None)

foo_0 = Foo(name="0", b=True)
foo_1 = Foo(name="1", a=2)
foo_0 = Foo(name="0", my_bool=True)
foo_1 = Foo(name="1", my_int=2)
assert foo_0.pprint() != foo_1.pprint() != Foo().pprint()
for i, foo in enumerate((foo_0, foo_1)):
temp_file = f"{temp_dir}/{i}.{mode}"
Expand All @@ -221,6 +224,18 @@ class Foo(param.Parameterized):
assert options.p[0].pprint() == foo_0.pprint()
assert options.p[1].pprint() == foo_1.pprint()

with open(f"{temp_dir}/0.{mode}", "w") as f:
if mode.endswith("yaml"):
f.write("my_int: 'snarf'\n")
elif mode.endswith("json"):
f.write(r'{"my_int": "snarf"}')
else:
assert False, f"{mode} check missing"

with pytest.raises(SystemExit):
parser.parse_args(["--p", f"{temp_dir}/0.{mode}"])
assert capsys.readouterr().err.index("my_int") >= 0


def test_serialization_action(temp_dir, mode, capsys, yaml_loader):
class Bar(param.Parameterized):
Expand Down
10 changes: 9 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
# and then run "tox" from this directory.

[tox]
envlist = py3{7,8,9,10}-{pyyaml,ruamel}
envlist = py3{7,8,9,10,11}-{pyyaml,ruamel}
isolated_build = True

[gh]
python =
3.7 = py37-pyyaml, py37-ruamel
3.8 = py38-ruamel
3.9 = py38-ruamel
3.10 = py310-ruamel
3.11 = py311-ruamel

[testenv]
deps =
ruamel: ruamel.yaml>=0.15
Expand Down

0 comments on commit bddf658

Please sign in to comment.