Remember when we switched to py.test? Yeah well, we lost half the tests on the way there.

This commit is contained in:
enkore 2014-10-17 16:12:59 +02:00
parent 34a71d8fd4
commit 95718c27a8
2 changed files with 14 additions and 17 deletions

View File

@ -5,16 +5,13 @@ import unittest
from i3pystatus import battery
def factory(path, format, expected):
def test():
bc = battery.BatteryChecker(path=path, format=format)
bc.run()
assert bc.output["full_text"] == expected
test.description = path + ":" + format
return test
def battery_test(path, format, expected):
bc = battery.BatteryChecker(path=path, format=format)
bc.run()
assert bc.output["full_text"] == expected
def basic_test_generator():
def test_basic():
cases = [
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
@ -26,6 +23,6 @@ def basic_test_generator():
("test_battery_broken1", "FULL", "0.000", "0h:00m"),
]
for path, status, consumption, remaining in cases:
yield factory(path, "{status}", status)
yield factory(path, "{consumption:.3f}", consumption)
yield factory(path, "{remaining:%hh:%Mm}", remaining)
battery_test(path, "{status}", status)
battery_test(path, "{consumption:.3f}", consumption)
battery_test(path, "{remaining:%hh:%Mm}", remaining)

View File

@ -29,7 +29,7 @@ def partition(iterable, limit, assrt):
assert sorted(item) in partitions
def partition_test_generator():
def test_partition():
cases = [
([1, 2, 3, 4], 3, [[1, 2], [3], [4]]),
([2, 1, 3, 4], 3, [[1, 2], [3], [4]]),
@ -38,14 +38,14 @@ def partition_test_generator():
]
for iterable, limit, assrt in cases:
yield partition, iterable, limit, assrt
partition(iterable, limit, assrt)
def popwhile(iterable, predicate, assrt):
assert list(util.popwhile(predicate, iterable)) == assrt
def popwhile_test_generator():
def test_popwhile():
cases = [
([1, 2, 3, 4], lambda x: x < 2, []),
([1, 2, 3, 4], lambda x: x < 5 and x > 2, [4, 3]),
@ -55,7 +55,7 @@ def popwhile_test_generator():
]
for iterable, predicate, assrt in cases:
yield popwhile, iterable, predicate, assrt
popwhile(iterable, predicate, assrt)
def keyconstraintdict_missing(valid, required, feedkeys, assrt_missing):
@ -65,7 +65,7 @@ def keyconstraintdict_missing(valid, required, feedkeys, assrt_missing):
assert kcd.missing() == set(assrt_missing)
def keyconstraintdict_missing_test_generator():
def test_keyconstraintdict_missing():
cases = [
# ( valid, required, feed, missing )
(("foo", "bar", "baz"), ("foo",), ("bar",), ("foo",)),
@ -76,7 +76,7 @@ def keyconstraintdict_missing_test_generator():
]
for valid, required, feed, missing in cases:
yield keyconstraintdict_missing, valid, required, feed, missing
keyconstraintdict_missing(valid, required, feed, missing)
class ModuleListTests(unittest.TestCase):