1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
"""Test functions of util.py ."""
import pytest
from cobra.util import AutoVivification, format_long_string, show_versions
@pytest.mark.parametrize(
"input_string, expected_string",
[
(
(
"This is a really long string, but is it long enough. "
"I hope it is long enough so that format_long_string() function works."
),
"This is a really long string, but is it long...",
),
("This is short string.", "This is short string."),
],
)
def test_format_long_string(input_string: str, expected_string: str) -> None:
"""Test functionality of format long string."""
assert expected_string == format_long_string(input_string)
def test_autovivification() -> None:
"""Test proper functionality of autovivification."""
test_data = AutoVivification()
test_data["a"]["b"] = 1
test_data["c"]["d"] = 2
assert test_data["a"] == {"b": 1}
assert test_data["c"] == {"d": 2}
assert test_data["a"]["b"] == 1
assert test_data["c"]["d"] == 2
@pytest.mark.xfail(reason="The binary doesn't seem to be built during build - this should simply xpass during autopkgtests")
def test_show_versions(capsys) -> None:
"""Test output of dependency information."""
show_versions()
captured = capsys.readouterr()
lines = captured.out.split("\n")
assert lines[1].startswith("Package Information")
assert lines[2].startswith("------------------")
assert lines[3].startswith("cobra")
assert lines[5].startswith("Dependency Information")
assert lines[6].startswith("------------------")
|