Skip to content

Commit 2f5d40b

Browse files
committed
Add tox for tests
Enable tox and clean up for lightweight tests. - Enable tox, testing, formatting and linting for all supported versions of Python - Clean out unused imports and replace wildcard imports with explicit imports I encountered this error on running tox: ``` AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'? ``` The fix was to replace my tox venv with a new one built from a recent version of Python and install it with an fresh installation of pipx.
1 parent be4a229 commit 2f5d40b

File tree

6 files changed

+44
-19
lines changed

6 files changed

+44
-19
lines changed

src/md_insights_client/exceptions.py

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ class ConfigurationError(Exception):
77

88
class FeedAccessError(Exception):
99
"Exception indicating a problem accessing the feed"
10-
11-
12-
__all__ = ["ConfigurationError", "FeedAccessError"]

src/md_insights_client/insights_snapshot.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55

66
import gzip
77
import logging
8-
import os
98
import re
109
import shutil
11-
import sys
1210
from argparse import ArgumentParser
1311
from datetime import datetime
1412
from importlib.metadata import version
1513

1614
import requests
1715

18-
from .exceptions import *
19-
from .settings import *
16+
from .exceptions import ConfigurationError, FeedAccessError
17+
from .settings import (
18+
CHOICE_LOG_LEVELS,
19+
CONFIG_FILE_DEFAULT,
20+
DEFAULT_LOGLEVEL,
21+
MD_INSIGHTS_API_HOST,
22+
SettingsLoader,
23+
)
2024

2125
__application_name__ = "md-insights-client"
2226
__version__ = version(__application_name__)
@@ -66,9 +70,8 @@ def fetch_feeds(api_key, feeds=[]):
6670
logging.error(
6771
"response body from server response: %s", response.text
6872
)
69-
parser.exit(
70-
status=1,
71-
message=f"API error attempting to retrieve feed {feed}: {e}\n",
73+
raise FeedAccessError(
74+
f"API error attempting to retrieve feed: {e}"
7275
)
7376

7477
# Extract filename from response header

src/md_insights_client/settings.py

-9
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,3 @@ def __init__(self, conf_file: str = CONFIG_FILE_DEFAULT):
5151

5252
def get_config(self):
5353
return self.config
54-
55-
56-
__all__ = [
57-
"CHOICE_LOG_LEVELS",
58-
"CONFIG_FILE_DEFAULT",
59-
"DEFAULT_LOGLEVEL",
60-
"MD_INSIGHTS_API_HOST",
61-
"SettingsLoader",
62-
]

tests/.keep

Whitespace-only changes.

tests/test_nop.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Tests."""
2+
3+
4+
def test_always_passes():
5+
"""Test that always passes."""
6+
assert True

tox.ini

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[tox]
2+
requires =
3+
tox
4+
env_list = format, lint, py{39,310,311,312,313}
5+
6+
[testenv]
7+
description = run unit tests
8+
deps =
9+
pytest
10+
pytest-sugar
11+
commands =
12+
pytest {posargs:tests}
13+
14+
[testenv:format]
15+
description = run formatters
16+
skip_install = true
17+
deps =
18+
black
19+
commands =
20+
black -l 79 {posargs:src}
21+
22+
[testenv:lint]
23+
description = run linters
24+
skip_install = true
25+
deps =
26+
flake8
27+
commands =
28+
flake8 {posargs:src}

0 commit comments

Comments
 (0)