Replace DIY parametrized tests with @pytest.mark.parametrize

This commit is contained in:
enkore 2015-06-24 11:01:41 +02:00
parent 302bf38f00
commit 1532040f0b
2 changed files with 45 additions and 60 deletions

View File

@ -2,6 +2,8 @@
import os.path
import pytest
from i3pystatus import battery
@ -11,8 +13,7 @@ def battery_test(path, format, expected):
assert bc.output["full_text"] == expected
def test_basic():
cases = [
@pytest.mark.parametrize("path, status, consumption, remaining", [
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
("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_broken1", "FULL", "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, "{consumption:.3f}", consumption)
battery_test(path, "{remaining:%hh:%Mm}", remaining)

View File

@ -6,6 +6,8 @@ import string
import random
import types
import pytest
from i3pystatus.core.exceptions import ConfigAmbigiousClassesError, ConfigInvalidModuleError
from i3pystatus.core import util, ClassFinder
@ -22,61 +24,43 @@ def test_lchop_unmatched():
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 = [sorted(partition) for partition in partitions]
for item in assrt:
assert sorted(item) in partitions
def test_partition():
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 = [
@pytest.mark.parametrize("iterable, predicate, assrt", [
([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 == 4, [4]),
([1, 2, 3, 4], lambda x: True, [4, 3, 2, 1]),
([1, 2], lambda x: False, []),
]
for iterable, predicate, assrt in cases:
popwhile(iterable, predicate, assrt)
])
def test_popwhile(iterable, predicate, assrt):
assert list(util.popwhile(predicate, iterable)) == assrt
def keyconstraintdict_missing(valid, required, feedkeys, assrt_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 = [
@pytest.mark.parametrize("valid, required, feed, missing", [
# ( valid, required, feed, missing )
(("foo", "bar", "baz"), ("foo",), ("bar",), ("foo",)),
(("foo", "bar", "baz"), ("foo",), tuple(), ("foo",)),
(("foo", "bar", "baz"), ("bar", "baz"), ("bar", "baz"), tuple()),
(("foo", "bar", "baz"), ("bar", "baz"),
("bar", "foo", "baz"), tuple()),
]
(("foo", "bar", "baz"), ("bar", "baz"), ("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):