Replace DIY parametrized tests with @pytest.mark.parametrize
This commit is contained in:
parent
302bf38f00
commit
1532040f0b
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from i3pystatus import battery
|
from i3pystatus import battery
|
||||||
|
|
||||||
|
|
||||||
@ -11,8 +13,7 @@ def battery_test(path, format, expected):
|
|||||||
assert bc.output["full_text"] == expected
|
assert bc.output["full_text"] == expected
|
||||||
|
|
||||||
|
|
||||||
def test_basic():
|
@pytest.mark.parametrize("path, status, consumption, remaining", [
|
||||||
cases = [
|
|
||||||
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
|
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
|
||||||
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
|
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
|
||||||
("test_battery_basic3", "DIS", "15.624", "4h:04m"),
|
("test_battery_basic3", "DIS", "15.624", "4h:04m"),
|
||||||
@ -23,8 +24,8 @@ def test_basic():
|
|||||||
("test_battery_132", "DIS", "8.370", "1h:17m"),
|
("test_battery_132", "DIS", "8.370", "1h:17m"),
|
||||||
("test_battery_broken1", "FULL", "0.000", "0h:00m"),
|
("test_battery_broken1", "FULL", "0.000", "0h:00m"),
|
||||||
("test_battery_issue89_2", "DIS", "0.000", "0h:00m"),
|
("test_battery_issue89_2", "DIS", "0.000", "0h:00m"),
|
||||||
]
|
])
|
||||||
for path, status, consumption, remaining in cases:
|
def test_basic(path, status, consumption, remaining):
|
||||||
battery_test(path, "{status}", status)
|
battery_test(path, "{status}", status)
|
||||||
battery_test(path, "{consumption:.3f}", consumption)
|
battery_test(path, "{consumption:.3f}", consumption)
|
||||||
battery_test(path, "{remaining:%hh:%Mm}", remaining)
|
battery_test(path, "{remaining:%hh:%Mm}", remaining)
|
||||||
|
@ -6,6 +6,8 @@ import string
|
|||||||
import random
|
import random
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from i3pystatus.core.exceptions import ConfigAmbigiousClassesError, ConfigInvalidModuleError
|
from i3pystatus.core.exceptions import ConfigAmbigiousClassesError, ConfigInvalidModuleError
|
||||||
from i3pystatus.core import util, ClassFinder
|
from i3pystatus.core import util, ClassFinder
|
||||||
|
|
||||||
@ -22,61 +24,43 @@ def test_lchop_unmatched():
|
|||||||
assert util.lchop("12345", "345") == "12345"
|
assert util.lchop("12345", "345") == "12345"
|
||||||
|
|
||||||
|
|
||||||
def partition(iterable, limit, assrt):
|
@pytest.mark.parametrize("iterable, limit, assrt", [
|
||||||
|
([1, 2, 3, 4], 3, [[1, 2], [3], [4]]),
|
||||||
|
([2, 1, 3, 4], 3, [[1, 2], [3], [4]]),
|
||||||
|
([0.33, 0.45, 0.89], 1, [[0.33, 0.45, 0.89]]),
|
||||||
|
([], 10, []),
|
||||||
|
])
|
||||||
|
def test_partition(iterable, limit, assrt):
|
||||||
partitions = util.partition(iterable, limit)
|
partitions = util.partition(iterable, limit)
|
||||||
partitions = [sorted(partition) for partition in partitions]
|
partitions = [sorted(partition) for partition in partitions]
|
||||||
for item in assrt:
|
for item in assrt:
|
||||||
assert sorted(item) in partitions
|
assert sorted(item) in partitions
|
||||||
|
|
||||||
|
|
||||||
def test_partition():
|
@pytest.mark.parametrize("iterable, predicate, assrt", [
|
||||||
cases = [
|
|
||||||
([1, 2, 3, 4], 3, [[1, 2], [3], [4]]),
|
|
||||||
([2, 1, 3, 4], 3, [[1, 2], [3], [4]]),
|
|
||||||
([0.33, 0.45, 0.89], 1, [[0.33, 0.45, 0.89]]),
|
|
||||||
([], 10, []),
|
|
||||||
]
|
|
||||||
|
|
||||||
for iterable, limit, assrt in cases:
|
|
||||||
partition(iterable, limit, assrt)
|
|
||||||
|
|
||||||
|
|
||||||
def popwhile(iterable, predicate, assrt):
|
|
||||||
assert list(util.popwhile(predicate, iterable)) == assrt
|
|
||||||
|
|
||||||
|
|
||||||
def test_popwhile():
|
|
||||||
cases = [
|
|
||||||
([1, 2, 3, 4], lambda x: x < 2, []),
|
([1, 2, 3, 4], lambda x: x < 2, []),
|
||||||
([1, 2, 3, 4], lambda x: x < 5 and x > 2, [4, 3]),
|
([1, 2, 3, 4], lambda x: x < 5 and x > 2, [4, 3]),
|
||||||
([1, 2, 3, 4], lambda x: x == 4, [4]),
|
([1, 2, 3, 4], lambda x: x == 4, [4]),
|
||||||
([1, 2, 3, 4], lambda x: True, [4, 3, 2, 1]),
|
([1, 2, 3, 4], lambda x: True, [4, 3, 2, 1]),
|
||||||
([1, 2], lambda x: False, []),
|
([1, 2], lambda x: False, []),
|
||||||
]
|
])
|
||||||
|
def test_popwhile(iterable, predicate, assrt):
|
||||||
for iterable, predicate, assrt in cases:
|
assert list(util.popwhile(predicate, iterable)) == assrt
|
||||||
popwhile(iterable, predicate, assrt)
|
|
||||||
|
|
||||||
|
|
||||||
def keyconstraintdict_missing(valid, required, feedkeys, assrt_missing):
|
@pytest.mark.parametrize("valid, required, feed, missing", [
|
||||||
kcd = util.KeyConstraintDict(valid_keys=valid, required_keys=required)
|
|
||||||
kcd.update(dict.fromkeys(feedkeys))
|
|
||||||
|
|
||||||
assert kcd.missing() == set(assrt_missing)
|
|
||||||
|
|
||||||
|
|
||||||
def test_keyconstraintdict_missing():
|
|
||||||
cases = [
|
|
||||||
# ( valid, required, feed, missing )
|
# ( valid, required, feed, missing )
|
||||||
(("foo", "bar", "baz"), ("foo",), ("bar",), ("foo",)),
|
(("foo", "bar", "baz"), ("foo",), ("bar",), ("foo",)),
|
||||||
(("foo", "bar", "baz"), ("foo",), tuple(), ("foo",)),
|
(("foo", "bar", "baz"), ("foo",), tuple(), ("foo",)),
|
||||||
(("foo", "bar", "baz"), ("bar", "baz"), ("bar", "baz"), tuple()),
|
(("foo", "bar", "baz"), ("bar", "baz"), ("bar", "baz"), tuple()),
|
||||||
(("foo", "bar", "baz"), ("bar", "baz"),
|
(("foo", "bar", "baz"), ("bar", "baz"), ("bar", "foo", "baz"), tuple()),
|
||||||
("bar", "foo", "baz"), tuple()),
|
|
||||||
]
|
|
||||||
|
|
||||||
for valid, required, feed, missing in cases:
|
])
|
||||||
keyconstraintdict_missing(valid, required, feed, missing)
|
def test_keyconstraintdict_missing(valid, required, feed, missing):
|
||||||
|
kcd = util.KeyConstraintDict(valid_keys=valid, required_keys=required)
|
||||||
|
kcd.update(dict.fromkeys(feed))
|
||||||
|
|
||||||
|
assert kcd.missing() == set(missing)
|
||||||
|
|
||||||
|
|
||||||
class ModuleListTests(unittest.TestCase):
|
class ModuleListTests(unittest.TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user