[lint] Add lint and tests.

This commit is contained in:
Mikaël Capelle
2019-11-28 16:53:00 +01:00
parent e42e97064a
commit 800de70a43
8 changed files with 348 additions and 108 deletions

View File

@@ -0,0 +1,83 @@
# -*- encoding: utf-8 -*-
from simplex.magic_dictionary import magic_dictionary
def test_basic():
""" Tests that a non-customized magic_dictionary acts
as a standard python dictionary. """
d = magic_dictionary()
assert len(d) == 0
d["x"] = 1
d["y"] = "2"
assert len(d) == 2
assert d["x"] == 1
assert d["y"] == "2"
# Test copy:
d2 = magic_dictionary(d)
assert len(d2) == 2
assert d2["x"] == 1
assert d2["y"] == "2"
# Test construction:
d2 = magic_dictionary({"x": 1, "y": "2"})
assert len(d2) == 2
assert d2["x"] == 1
assert d2["y"] == "2"
# Test construction:
d2 = magic_dictionary(x=1, y="2")
assert len(d2) == 2
assert d2["x"] == 1
assert d2["y"] == "2"
# Test construction:
d2 = magic_dictionary((("x", 1), ("y", "2")))
assert len(d2) == 2
assert d2["x"] == 1
assert d2["y"] == "2"
def test_value_converter():
""" Tests that conversion is correctly done. """
# Convert a value to its string representation:
def converter(x):
return str(x)
d = magic_dictionary(value_converter=converter)
assert len(d) == 0
d["x"] = 2
d["y"] = 3
assert len(d) == 2
assert d["x"] == "2"
assert d["y"] == "3"
# Construction:
d = magic_dictionary(d, value_converter=converter)
assert len(d) == 2
assert d["x"] == "2"
assert d["y"] == "3"
# Construction:
d = magic_dictionary({"x": 2, "y": 3}, value_converter=converter)
assert len(d) == 2
assert d["x"] == "2"
assert d["y"] == "3"
# Construction:
d = magic_dictionary(x=2, y=3, value_converter=converter)
assert len(d) == 2
assert d["x"] == "2"
assert d["y"] == "3"
# Construction:
d = magic_dictionary([("x", 2), ("y", 3)], value_converter=converter)
assert len(d) == 2
assert d["x"] == "2"
assert d["y"] == "3"