Skip to content

Commit 621099c

Browse files
mraspberryBeyondEvil
authored andcommitted
Add support for toml-formatted variables (#27)
* Add support for toml-formatted variables
1 parent c3f529b commit 621099c

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ black = "*"
1111
pre-commit = "*"
1212

1313
[packages]
14-
pytest-variables = {editable = true,extras = ["hjson", "yaml"],path = "."}
14+
pytest-variables = {editable = true,extras = ["hjson", "yaml", "toml"],path = "."}

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ to one of the following:
8383

8484
To learn more about the loader, see `here <https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation>`_
8585

86+
TOML
87+
~~~~~~~~~~
88+
89+
TOML_ aims to be a minimal configuration file format that's easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table.
90+
To install TOML support:
91+
92+
.. code-block:: bash
93+
94+
$ pip install pytest-variables[toml]
95+
8696
Contributing
8797
------------
8898

@@ -174,6 +184,7 @@ Resources
174184
.. _pytest: http://pytest.org
175185
.. _Human JSON: http://hjson.org
176186
.. _YAML: http://yaml.org
187+
.. _TOML: https://github.com/toml-lang/toml
177188
.. _dictionary: https://docs.python.org/tutorial/datastructures.html#dictionaries
178189
.. _Release Notes: http://github.com/pytest-dev/pytest-variables/blob/master/CHANGES.rst
179190
.. _Issue Tracker: http://github.com/pytest-dev/pytest-variables/issues

pytest_variables/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def default(module, path, loader):
2626
"hjson": ("hjson", default),
2727
"yml": ("yaml", default),
2828
"yaml": ("yaml", default),
29+
"toml": ("toml", default),
2930
}
3031

3132

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
entry_points={"pytest11": ["variables = pytest_variables.plugin"]},
1313
install_requires=["pytest>=2.4.2"],
1414
setup_requires=["setuptools_scm"],
15-
extras_require={"hjson": ["hjson"], "yaml": ["PyYAML"]},
15+
extras_require={"hjson": ["hjson"], "yaml": ["PyYAML"], "toml": ["toml"]},
1616
license="Mozilla Public License 2.0 (MPL 2.0)",
1717
keywords="py.test pytest json variables",
1818
classifiers=[

test_variables.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def pytest_generate_tests(metafunc):
1111
if "file_format" in metafunc.fixturenames:
12-
metafunc.parametrize("file_format", ["json", "hjson", "yaml"])
12+
metafunc.parametrize("file_format", ["json", "hjson", "yaml", "toml"])
1313

1414

1515
def run(testdir, file_format="json", variables=None, raw=False):
@@ -22,6 +22,9 @@ def run(testdir, file_format="json", variables=None, raw=False):
2222
elif file_format == "yaml" and not raw:
2323
yaml = pytest.importorskip("yaml")
2424
v = yaml.dump(v)
25+
elif file_format == "toml" and not raw:
26+
toml = pytest.importorskip("toml")
27+
v = toml.dumps(v)
2528
elif not raw:
2629
import json
2730

@@ -84,7 +87,7 @@ def test(variables):
8487

8588
def test_invalid_format(testdir, file_format):
8689
testdir.makepyfile("def test(variables): pass")
87-
result = run(testdir, file_format, ["invalid"], raw=True)
90+
result = run(testdir, file_format, ["invalid="], raw=True)
8891
assert result.ret == 3
8992
result.stderr.fnmatch_lines(["*ValueError: Unable to parse*"])
9093

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ deps =
1212
pytest
1313
hjson
1414
PyYAML
15+
toml
1516
commands = pytest -v -r a {posargs}
1617

1718
[testenv:linting]

0 commit comments

Comments
 (0)