Skip to content

Commit

Permalink
refactor: simplify dependency information (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnighter committed May 14, 2018
1 parent 17177d2 commit 1c37dc0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 140 deletions.
11 changes: 7 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Please explain:

#### Code Sample

Create a [minimal, complete, verifiable example
](https://stackoverflow.com/help/mcve).
Create a [minimal, complete, verifiable example](https://stackoverflow.com/help/mcve).

```python
# Paste your code here.
Expand All @@ -20,9 +19,13 @@ Create a [minimal, complete, verifiable example

#### Expected Output

#### Output of `cobra.show_versions()`
#### Dependency Information

Please paste the output of `python -c "from cobra import show_versions;
show_versions()"` in the details block below.

<details>
# Paste the output of `import cobra;cobra.show_versions()` here.

[Paste output here.]

</details>
2 changes: 1 addition & 1 deletion cobra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cobra import flux_analysis, io
from cobra.core import (
DictList, Gene, Metabolite, Model, Object, Reaction, Species)
from cobra.util.version_info import show_versions
from cobra.util import show_versions

__version__ = "0.11.3"

Expand Down
67 changes: 12 additions & 55 deletions cobra/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import pytest
from six.moves import range

from cobra import DictList, Object
from cobra.util.version_info import (
get_sys_info, get_pkg_info, show_versions, SYS_ORDER, PKG_ORDER)
from cobra import DictList, Object, show_versions


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -297,56 +295,15 @@ def test_union(self, dict_list):
assert test_list.index("test2") == 1


class TestVersionInfo:
SKIP_OPTIONAL = frozenset([
"cobra", "python-libsbml", "lxml", "matplotlib", "palettable", "scipy",
"pymatbridge"])
def test_show_versions(capsys):
show_versions()
captured = capsys.readouterr()
lines = captured.out.split("\n")
assert lines[1].startswith("System Information")
assert lines[2].startswith("==================")
assert lines[3].startswith("OS")
assert lines[4].startswith("OS-release")
assert lines[5].startswith("Python")

@pytest.fixture(scope="module")
def sys_info(self):
return get_sys_info()

@pytest.fixture(scope="module")
def pkg_info(self):
return get_pkg_info()

@pytest.mark.parametrize("key", SYS_ORDER)
def test_sys_info_key(self, key, sys_info):
assert key in sys_info

@pytest.mark.parametrize("key", SYS_ORDER)
def test_sys_info_value(self, key, sys_info):
assert len(sys_info[key]) > 0

@pytest.mark.parametrize("key", PKG_ORDER)
def test_pkg_info_key(self, key, pkg_info):
if key in self.SKIP_OPTIONAL:
pytest.skip()
assert key in pkg_info

@pytest.mark.parametrize("key", PKG_ORDER)
def test_pkg_info_value(self, key, pkg_info):
if key in self.SKIP_OPTIONAL:
pytest.skip()
assert len(pkg_info[key]) > 0

def test_show_versions(self, sys_info, pkg_info, capsys):
show_versions()
out, err = capsys.readouterr()
lines = out.split("\n")
i = 3
for key in SYS_ORDER:
line = lines[i]
assert line.startswith(key)
assert line.endswith(sys_info[key])
i += 1
i += 3
for key in PKG_ORDER:
line = lines[i]
if key in self.SKIP_OPTIONAL:
if line.startswith(key):
i += 1
continue
assert line.startswith(key)
assert line.endswith(pkg_info[key])
i += 1
assert lines[7].startswith("Package Versions")
assert lines[8].startswith("================")
7 changes: 7 additions & 0 deletions cobra/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import absolute_import

from depinfo import print_dependencies


def format_long_string(string, max_length=50):
if len(string) > max_length:
Expand All @@ -20,3 +22,8 @@ def __getitem__(self, item):
except KeyError:
value = self[item] = type(self)()
return value


def show_versions():
"""Print dependency information."""
print_dependencies("cobra")
79 changes: 0 additions & 79 deletions cobra/util/version_info.py

This file was deleted.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"numpy>=1.13",
"pandas>=0.17.0",
"optlang>=1.2.5",
"tabulate"
"tabulate",
"depinfo"
],
tests_require=[
"jsonschema > 2.5",
Expand Down

0 comments on commit 1c37dc0

Please sign in to comment.