Skip to content

Commit

Permalink
Merge pull request #87 from seddonym/adjust-build-link
Browse files Browse the repository at this point in the history
Change travis-ci.org to travis-ci.com
  • Loading branch information
seddonym committed Sep 17, 2020
2 parents a3cea0f + 5eb2af4 commit 2255ce8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ For merging, you should:
4. Add yourself to ``AUTHORS.rst``.

.. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will
`run the tests <https://travis-ci.org/seddonym/import-linter/pull_requests>`_ for each change you add in the pull request.
`run the tests <https://travis-ci.com/seddonym/import-linter/pull_requests>`_ for each change you add in the pull request.
It will be slower though ...
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Import Linter
:alt: Python versions
:target: https://pypi.org/project/import-linter/

.. image:: https://api.travis-ci.org/seddonym/import-linter.svg?branch=master
:target: https://travis-ci.org/seddonym/import-linter
.. image:: https://api.travis-ci.com/seddonym/import-linter.svg?branch=master
:target: https://travis-ci.com/seddonym/import-linter


Import Linter allows you to define and enforce rules for the imports within and between Python packages.
Expand Down
4 changes: 1 addition & 3 deletions src/importlinter/contracts/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def check(self, graph: ImportGraph) -> ContractCheck:
invalid_chains = []

direct_imports_to_ignore = self.ignore_imports if self.ignore_imports else []
helpers.pop_imports(
graph, direct_imports_to_ignore # type: ignore
)
helpers.pop_imports(graph, direct_imports_to_ignore) # type: ignore

if self.containers:
self._validate_containers(graph)
Expand Down
19 changes: 4 additions & 15 deletions tests/unit/domain/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
from grimp.adaptors.graph import ImportGraph

from grimp.adaptors.graph import ImportGraph # type: ignore
from importlinter.domain.helpers import add_imports


def test_add_imports():
graph = ImportGraph()
import_details = [
{
'importer': 'a',
'imported': 'b',
'line_number': 1,
'line_contents': 'lorem ipsum',
},
{
'importer': 'c',
'imported': 'd',
'line_number': 2,
'line_contents': 'lorem ipsum 2',
}
{"importer": "a", "imported": "b", "line_number": 1, "line_contents": "lorem ipsum"},
{"importer": "c", "imported": "d", "line_number": 2, "line_contents": "lorem ipsum 2"},
]
assert not graph.modules
add_imports(graph, import_details)
assert graph.modules == {'a', 'b', 'c', 'd'}
assert graph.modules == {"a", "b", "c", "d"}
71 changes: 39 additions & 32 deletions tests/unit/domain/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from contextlib import contextmanager

import pytest

from importlinter.domain.imports import Module, DirectImport
from importlinter.domain.imports import DirectImport, Module


@contextmanager
Expand All @@ -12,32 +11,40 @@ def does_not_raise():

class TestModule:
def test_object_representation(self):
test_object = Module('new_module')
assert repr(test_object) == '<Module: new_module>'
test_object = Module("new_module")
assert repr(test_object) == "<Module: new_module>"

@pytest.mark.parametrize(('first_object', 'second_object', 'expected_bool'),
[
(Module('first'), Module('second'), False),
(Module('same'), Module('same'), True),
(Module('different'), 'different', False),
])
@pytest.mark.parametrize(
("first_object", "second_object", "expected_bool"),
[
(Module("first"), Module("second"), False),
(Module("same"), Module("same"), True),
(Module("different"), "different", False),
],
)
def test_equal_magic_method(self, first_object, second_object, expected_bool):
comparison_result = first_object == second_object
assert comparison_result is expected_bool

@pytest.mark.parametrize(('module', 'expected_parent', 'exception'), [
(Module('parent.child'), Module('parent'), does_not_raise()),
(Module('child'), Module(''), pytest.raises(ValueError)),
])
@pytest.mark.parametrize(
("module", "expected_parent", "exception"),
[
(Module("parent.child"), Module("parent"), does_not_raise()),
(Module("child"), Module(""), pytest.raises(ValueError)),
],
)
def test_parent(self, module, expected_parent, exception):
with exception:
assert module.parent == expected_parent

@pytest.mark.parametrize(('child', 'parent', 'expected_bool'), [
(Module('parent.child'), Module('parent'), True),
(Module('grandparent.parent.child'), Module('grandparent'), False),
(Module('first_child'), Module('second_child'), False),
])
@pytest.mark.parametrize(
("child", "parent", "expected_bool"),
[
(Module("parent.child"), Module("parent"), True),
(Module("grandparent.parent.child"), Module("grandparent"), False),
(Module("first_child"), Module("second_child"), False),
],
)
def test_is_child_of(self, child, parent, expected_bool):
assert child.is_child_of(parent) is expected_bool

Expand All @@ -48,24 +55,24 @@ def test_object_representation(self):
importer=Module("mypackage.foo"),
imported=Module("mypackage.bar"),
)
assert repr(test_object) == '<DirectImport: mypackage.foo -> mypackage.bar>'
assert repr(test_object) == "<DirectImport: mypackage.foo -> mypackage.bar>"

@pytest.mark.parametrize(('test_object', 'expected_string'), [
(
DirectImport(
importer=Module("mypackage.foo"),
imported=Module("mypackage.bar")
),
'mypackage.foo -> mypackage.bar',
),
(
@pytest.mark.parametrize(
("test_object", "expected_string"),
[
(
DirectImport(importer=Module("mypackage.foo"), imported=Module("mypackage.bar")),
"mypackage.foo -> mypackage.bar",
),
(
DirectImport(
importer=Module("mypackage.foo"),
imported=Module("mypackage.bar"),
line_number=10,
),
'mypackage.foo -> mypackage.bar (l. 10)',
),
])
"mypackage.foo -> mypackage.bar (l. 10)",
),
],
)
def test_string_object_representation(self, test_object, expected_string):
assert str(test_object) == expected_string
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ commands =

[testenv:check]
deps =
black==19.3b0
black==20.8b1
flake8==3.7.8
mypy==0.730
commands =
Expand Down

0 comments on commit 2255ce8

Please sign in to comment.