Skip to content

Commit

Permalink
style: conform to style suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorres committed Aug 13, 2023
1 parent cb941fc commit 84560aa
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 55 deletions.
73 changes: 72 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ toml = "^0.10.2"

[tool.poetry.dev-dependencies]
pre-commit = "^3.3.3"
black = "^23.7.0"
isort = "^5.12.0"
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
Expand All @@ -46,6 +47,18 @@ types-termcolor = "^1.1.6.2"
types-toml = "^0.10.8.7"
types-requests = "^2.31.0.2"

[tool.isort]
src_paths = ["lancini", "test"]
profile = "black"
line_length = 90

[tool.mypy]
warn_return_any = true
warn_unused_configs = true

[tool.pylint.FORMAT]
max-line-length=90

[tool.poetry.scripts]
oneup = 'oneup.cli:main'

Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
exclude =
.git,
__pycache__,
build,
dist,
env
max-complexity = 10
max-line-length = 90
73 changes: 20 additions & 53 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Final

import pytest

from oneup import cli

SAMPLE_FILES_PATH: Final[Path] = Path("tests/sample_files")
Expand All @@ -24,9 +23,7 @@ def test_get_parser() -> None:
assert parser.epilog == "Happy coding! :-)"


def test_discover_all_requirement_files(
monkeypatch: pytest.MonkeyPatch
) -> None:
def test_discover_all_requirement_files(monkeypatch: pytest.MonkeyPatch) -> None:
"""
Unit tests that make sure that file discovery is working as expected.
"""
Expand All @@ -39,31 +36,13 @@ def test_discover_all_requirement_files(
monkeypatch.setattr("os.listdir", lambda: ["test", "another_test.txt"])
assert cli.discover_all_requirement_files() == []

monkeypatch.setattr(
"os.listdir",
lambda: [
"requirements.txt",
"another_test.txt"
]
)
monkeypatch.setattr("os.listdir", lambda: ["requirements.txt", "another_test.txt"])
assert cli.discover_all_requirement_files() == [Path("requirements.txt")]

monkeypatch.setattr(
"os.listdir",
lambda: [
"pyproject.toml",
"another_test.txt"
]
)
monkeypatch.setattr("os.listdir", lambda: ["pyproject.toml", "another_test.txt"])
assert cli.discover_all_requirement_files() == [Path("pyproject.toml")]

monkeypatch.setattr(
"os.listdir",
lambda: [
"pyproject.toml",
"requirements.txt"
]
)
monkeypatch.setattr("os.listdir", lambda: ["pyproject.toml", "requirements.txt"])
assert cli.discover_all_requirement_files() == [
Path("pyproject.toml"),
Path("requirements.txt"),
Expand All @@ -77,7 +56,7 @@ def test_discover_all_requirement_files(
"this is not a requirements file.txt",
"not requirements.txt",
"definitely not a pyproject.toml",
]
],
)
assert cli.discover_all_requirement_files() == []

Expand All @@ -104,43 +83,28 @@ def test_discover_requirement_file(monkeypatch: pytest.MonkeyPatch) -> None:
is behaving properly
"""

monkeypatch.setattr(
cli,
"discover_all_requirement_files",
lambda: None
)
monkeypatch.setattr(cli, "discover_all_requirement_files", lambda: None)
assert cli.discover_requirement_file(True) is None
assert cli.discover_requirement_file(False) is None

monkeypatch.setattr(
cli,
"discover_all_requirement_files",
lambda: [Path("requirements.txt")]
cli, "discover_all_requirement_files", lambda: [Path("requirements.txt")]
)
assert cli.discover_requirement_file(True) == Path("requirements.txt")
assert cli.discover_requirement_file(False) == Path("requirements.txt")

monkeypatch.setattr(
cli,
"discover_all_requirement_files",
lambda: [Path("requirements.txt"), Path("pyproject.toml")]
)
assert (
cli.discover_requirement_file(False)
== Path("requirements.txt")
lambda: [Path("requirements.txt"), Path("pyproject.toml")],
)
assert cli.discover_requirement_file(False) == Path("requirements.txt")

monkeypatch.setattr('builtins.input', lambda _: "0")
assert (
cli.discover_requirement_file(True)
== Path("requirements.txt")
)
monkeypatch.setattr("builtins.input", lambda _: "0")
assert cli.discover_requirement_file(True) == Path("requirements.txt")

monkeypatch.setattr('builtins.input', lambda _: "1")
assert (
cli.discover_requirement_file(True)
== Path("pyproject.toml")
)
monkeypatch.setattr("builtins.input", lambda _: "1")
assert cli.discover_requirement_file(True) == Path("pyproject.toml")


def test_get_dependencies_from_pyproject_file() -> None:
Expand Down Expand Up @@ -213,13 +177,15 @@ def test_get_dependencies_from_pyproject_file() -> None:
"dev-dependencies": {
"package3": "1.2.3",
"package4": "4.5.6",
}
},
}
}
}
) == ["package1", "package2", "package3", "package4"]

assert cli.get_dependencies_from_pyproject_file({}) == []
output = cli.get_dependencies_from_pyproject_file({})
expected: list[str] = []
assert output == expected


def test_scan_file(monkeypatch: pytest.MonkeyPatch) -> None:
Expand All @@ -234,8 +200,9 @@ def mock_print_project_latest_version_and_url(dependency: str) -> None:
printed_dependencies.append(dependency)

monkeypatch.setattr(
cli, "print_project_latest_version_and_url",
mock_print_project_latest_version_and_url
cli,
"print_project_latest_version_and_url",
mock_print_project_latest_version_and_url,
)

# case: requirements.txt
Expand Down
10 changes: 9 additions & 1 deletion tests/test_oneup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
"""
Collection of sanity tests for oneup module.
"""

from oneup import __version__


def test_version():
assert __version__ == '0.2.0'
"""
Tests that the oneup module is set to the correct version
"""

assert __version__ == "0.2.0"

0 comments on commit 84560aa

Please sign in to comment.