Skip to content

Commit

Permalink
Handle toml.decoder.InlineTableDict in AdvancedDataRegressionFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Mar 22, 2021
1 parent b6c7574 commit 569f17e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion coincidence/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
# stdlib
import collections
from collections import ChainMap, Counter, OrderedDict, defaultdict
from contextlib import suppress
from functools import partial
from types import MappingProxyType
from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Type, TypeVar, Union
from typing import Any, Callable, cast, Dict, Mapping, Optional, Sequence, Type, TypeVar, Union

# 3rd party
import pytest
Expand Down Expand Up @@ -231,6 +232,7 @@ def _represent_sequences(dumper: RegressionYamlDumper, data):
data = dict(data._asdict())
else:
data = list(data)

return dumper.represent_data(data)


Expand All @@ -240,6 +242,12 @@ def _represent_captureresult(dumper: RegressionYamlDumper, data):
return dumper.represent_data(data)


with suppress(TypeError):
# 3rd party
import toml
_representer_for(toml.decoder.InlineTableDict)(_represent_mappings) # type: ignore


@pytest.fixture()
def advanced_data_regression(datadir, original_datadir, request) -> AdvancedDataRegressionFixture:
"""
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ iniconfig!=1.1.0,>=1.0.1
pytest-cov>=2.8.1
pytest-randomly>=3.3.1
pytest-timeout>=1.4.2
toml>=0.10.2
5 changes: 5 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# 3rd party
import pytest
import toml
from domdf_python_tools.compat import PYPY37
from domdf_python_tools.paths import PathPlus
from domdf_python_tools.stringlist import StringList
Expand Down Expand Up @@ -63,6 +64,9 @@ def __len__(self):
return len(self._elements)


some_toml = "[section]\ntable = {a = 1, b = 2, c = 3}"


@pytest.mark.parametrize(
"data",
[
Expand Down Expand Up @@ -90,6 +94,7 @@ def __len__(self):
CustomSequence([MappingProxyType({'a': 1})]), id="Nested_CustomSequence_MappingProxyType"
),
pytest.param(CustomMapping({'a': Count(a=1, b=2, c=3)}), id="Nested_CustomMapping_NamedTuple"),
pytest.param(toml.loads(some_toml)["section"]["table"], id="Toml_InlineTableDict"),
]
)
def test_advanced_data_regression(advanced_data_regression, data):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a: 1
b: 2
c: 3

0 comments on commit 569f17e

Please sign in to comment.