Skip to content

Commit 2180c82

Browse files
committed
apply suggestions from code review
1 parent 1a7de66 commit 2180c82

File tree

8 files changed

+63
-23
lines changed

8 files changed

+63
-23
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ ignore =
66
W503
77
max-complexity = 10
88
max-line-length = 120
9-
select = E,W,F,C,N
9+
select = E,W,F,C,N

.github/workflows/test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
repo-token: ${{ secrets.GITHUB_TOKEN }}
3333
version: 3.x
3434

35+
- name: Build native
36+
shell: bash
37+
run: task build
38+
3539
- name: Cross-build for 386
3640
if: matrix.os != 'macos-latest'
3741
env:
@@ -44,10 +48,6 @@ jobs:
4448
GOARCH: "arm"
4549
run: task build
4650

47-
- name: Build native
48-
shell: bash
49-
run: task build
50-
5151
- name: Install Python
5252
uses: actions/setup-python@v2
5353
with:

Taskfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tasks:
4545
test-integration:
4646
desc: Run integration tests
4747
cmds:
48+
- task: build
4849
- poetry install --no-root
4950
- poetry run pytest test
5051

poetry.lock

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ python = "^3.8"
99
pytest = "6.1.2"
1010
invoke = "^1.5.0"
1111
semver = "^2.13.0"
12+
python-dateutil = "^2.8.1"
1213

1314
[tool.poetry.dev-dependencies]
1415
flake8 = "^3.9.2"
1516
black = "^21.5b1"
1617

1718
[tool.black]
1819
line-length = 120
19-
target-version = ["py38"]
20+
target-version = ["py38"]

test/conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,32 @@
1717

1818
import pathlib
1919
import platform
20+
import typing
2021
import invoke.context
2122
import pytest
2223

2324

2425
@pytest.fixture(scope="function")
25-
def run_command(pytestconfig, working_dir):
26+
def run_command(pytestconfig, working_dir) -> typing.Callable[..., invoke.runners.Result]:
2627
"""Provide a wrapper around invoke's `run` API so that every test will work in the same temporary folder.
28+
2729
Useful reference:
2830
http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Result
2931
"""
3032

3133
fwuploader_path = pathlib.Path(pytestconfig.rootdir).parent / "FirmwareUploader"
3234

33-
def _run(cmd_string, custom_working_dir=None, custom_env=None):
35+
def _run(
36+
cmd: list, custom_working_dir: typing.Optional[str] = None, custom_env: typing.Optional[dict] = None
37+
) -> invoke.runners.Result:
38+
if cmd is None:
39+
cmd = []
3440
if not custom_working_dir:
3541
custom_working_dir = working_dir
36-
cli_full_line = '"{}" {}'.format(fwuploader_path, cmd_string)
42+
quoted_cmd = []
43+
for token in cmd:
44+
quoted_cmd.append(f'"{token}"')
45+
cli_full_line = '"{}" {}'.format(fwuploader_path, " ".join(quoted_cmd))
3746
run_context = invoke.context.Context()
3847
# It might happen that we need to change directories between drives on Windows,
3948
# in that case the "/d" flag must be used otherwise directory wouldn't change

test/pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ filterwarnings =
66

77
# --capture=no - disable per-test capture
88
# --tb=long sets the length of the traceback in case of failures
9-
addopts = --capture=no --tb=long --verbose
9+
addopts = --capture=no --tb=long --verbose

test/test_main.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,30 @@
1717

1818
import json
1919
import semver
20-
21-
22-
def test_help(run_command):
23-
result = run_command("help")
24-
assert result.ok
25-
assert result.stderr == ""
26-
assert "Usage" in result.stdout
20+
import dateutil.parser
2721

2822

2923
def test_version(run_command):
30-
result = run_command("version")
24+
result = run_command(cmd=["version"])
3125
assert result.ok
32-
assert "Version:" in result.stdout
33-
assert "Commit:" in result.stdout
34-
assert "Date:" in result.stdout
26+
output_list = result.stdout.strip().split(sep=" ")
27+
assert output_list[0] == "FirmwareUploader"
28+
assert output_list[1] == "Version:"
29+
version = output_list[2]
30+
assert semver.VersionInfo.isvalid(version=version) or version == "git-snapshot" or "nightly" in version
31+
assert output_list[3] == "Commit:"
32+
assert isinstance(output_list[4], str)
33+
assert output_list[5] == "Date:"
34+
assert dateutil.parser.isoparse(output_list[6])
3535
assert "" == result.stderr
3636

37-
result = run_command("version --format json")
37+
result = run_command(cmd=["version", "--format", "json"])
3838
assert result.ok
3939
parsed_out = json.loads(result.stdout)
4040
assert parsed_out.get("Application", False) == "FirmwareUploader"
4141
version = parsed_out.get("VersionString", False)
4242
assert semver.VersionInfo.isvalid(version=version) or "git-snapshot" in version or "nightly" in version
43+
assert parsed_out.get("Commit", False) != ""
4344
assert isinstance(parsed_out.get("Commit", False), str)
45+
assert parsed_out.get("Date") != ""
4446
assert isinstance(parsed_out.get("Date", False), str)

0 commit comments

Comments
 (0)