Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
42525ba
Upgrade to GitHub-native Dependabot
dependabot-preview[bot] Apr 29, 2021
70206c5
fixed invalid int value in .pylintrc
blackbeareatsfish Jan 7, 2023
d9adea9
removed bad option values for --disable
blackbeareatsfish Jan 7, 2023
b173435
fixed C0209 lints in countdoom/cli.py
blackbeareatsfish Jan 7, 2023
da4094f
fixed C0209 lints in tests/test_cli.py
blackbeareatsfish Jan 7, 2023
ccbb67d
fixed C0209 lints in tests/test_client.py
blackbeareatsfish Jan 7, 2023
8db8ab3
fixed a C0209 bug in commits b173435 and da4094f
blackbeareatsfish Jan 7, 2023
91aa63c
fixed C0209 lints in tests/test_package.py
blackbeareatsfish Jan 7, 2023
e81d473
fixed R1732 lints in tests/test_package.py
blackbeareatsfish Jan 7, 2023
5869441
fixed W0707 lints in countdoom/client.py
blackbeareatsfish Jan 7, 2023
f678c30
python 3.5 has reached end of life, removing from tox
blackbeareatsfish Jan 8, 2023
1be3d33
remove python3.5 from travis
blackbeareatsfish Jan 8, 2023
83084c6
fixed E501 lint
blackbeareatsfish Jan 8, 2023
83f14bf
bugfix
blackbeareatsfish Jan 8, 2023
5a71783
added timeout to get request
blackbeareatsfish Jan 8, 2023
7e28325
replacing deprecated option
blackbeareatsfish Jan 8, 2023
df4405a
replaced collect-ignore with ignore option
blackbeareatsfish Jan 8, 2023
7265d57
switched to f-strings in setup.py
blackbeareatsfish Jan 8, 2023
b7c7a4f
added utf-8 encoding to open methods in setup.py
blackbeareatsfish Jan 8, 2023
0460edd
merged nested async with statements
blackbeareatsfish Jan 8, 2023
0214fbd
removed commented out code block
blackbeareatsfish Jan 8, 2023
17f3f20
line too long
blackbeareatsfish Jan 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "10:00"
open-pull-requests-limit: 10
6 changes: 2 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ ignore=conf.py
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"

[pre-commit-hook]
# C0122: Misplaced comparison constant (tests use Yoda conditions).
# C0330: Wrong hanging indentation (conflicts with `black`).
# W0621: Redefining name from outer scope (conflicts with pytest fixtures).
disable=C0122,C0330,W0621
limit=10.0
disable=W0621
limit=10
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python:
- "3.8"
- "3.7"
- "3.6"
- "3.5"
# Disabled until typed_ast (used by pylint) is fixed.
# See https://github.com/python/typed_ast/issues/134
# - "pypy3"
Expand Down
4 changes: 2 additions & 2 deletions countdoom/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def check_positive(value) -> int:
int_value = int(value)
if int_value <= 0:
raise argparse.ArgumentTypeError(
"{} is an invalid positive integer value".format(value)
f"{value} is an invalid positive integer value"
)
return int_value

Expand All @@ -127,7 +127,7 @@ def check_positive(value) -> int:
'--v',
'--version',
action='version',
version='%(prog)s {version}'.format(version=countdoom.__version__),
version=f'%(prog)s {countdoom.__version__}',
)
parser.add_argument(
'-h',
Expand Down
34 changes: 19 additions & 15 deletions countdoom/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,21 @@ async def _fetch(self, url: str, timeout: int = None) -> str:
raise CountdoomClientError("Session not started.")

try:
async with async_timeout.timeout(timeout):
async with self._session.get(url, timeout=timeout) as resp:
if resp.status != 200:
raise AssertionError
return await resp.text()
except AssertionError:
async with (
async_timeout.timeout(timeout),
self._session.get(url, timeout=timeout) as resp
):
if resp.status != 200:
raise AssertionError
return await resp.text()
except AssertionError as exc:
await self.close()
raise CountdoomClientError("Page not found.")
except OSError:
raise CountdoomClientError("Page not found.") from exc
except OSError as exc:
await self.close()
raise CountdoomClientError("Cannot connect to website. Check URL.")
raise CountdoomClientError(
"Cannot connect to website. Check URL."
) from exc

async def _extract_sentence(self) -> None:
"""
Expand All @@ -187,20 +191,20 @@ async def _extract_sentence(self) -> None:
self._sentence = re.sub(r'\s+', ' ', sentence).strip()
if not self._sentence:
raise ValueError()
except IndexError:
except IndexError as exc:
_LOGGER.error(
"No sentence found using selector %s. Check for source "
"website design changes.",
self.SELECTOR,
)
raise CountdoomClientError("No sentence found.")
except ValueError:
raise CountdoomClientError("No sentence found.") from exc
except ValueError as exc:
_LOGGER.error(
"Empty sentence found using selector %s. Check for source "
"website design changes.",
self.SELECTOR,
)
raise CountdoomClientError("Empty sentence found.")
raise CountdoomClientError("Empty sentence found.") from exc
_LOGGER.debug("Sentence found: %s", self._sentence)

async def close(self) -> None:
Expand All @@ -223,11 +227,11 @@ def _sentence_to_countdown(self) -> None:

try:
self._countdown = self.sentence_to_countdown(self._sentence)
except AttributeError:
except AttributeError as exc:
_LOGGER.error(
"Regex pattern yielded no result for : %s", self._sentence
)
raise CountdoomClientError("Sentence not parsable.")
raise CountdoomClientError("Sentence not parsable.") from exc
_LOGGER.debug("Countdown value: %s", self._countdown)

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ ignore_missing_imports = true
# Configure pytest
# See https://docs.pytest.org/
[tool:pytest]
collect_ignore = ['setup.py']
addopts = --strict
addopts =
--ignore=setup.py,
--strict-markers
markers =
live
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from setuptools import find_packages, setup

# Load documentation for PyPI.
with open('README.rst') as readme_file:
with open('README.rst', encoding="utf-8") as readme_file:
README = readme_file.read()

with open('CHANGELOG.rst') as history_file:
with open('CHANGELOG.rst', encoding="utf-8") as history_file:
HISTORY = history_file.read()

# Define extra requirements for different installation environments.
Expand Down Expand Up @@ -88,9 +88,9 @@

# Define URLs.
DOCS_URL = 'https://countdoom.readthedocs.io/'
HISTORY_URL = '{}en/latest/changelog.html'.format(DOCS_URL)
HISTORY_URL = f'{DOCS_URL}en/latest/changelog.html'
REPO_URL = 'https://github.com/renemarc/countdoom'
ISSUES_URL = '{}/issues'.format(REPO_URL)
ISSUES_URL = f'{REPO_URL}/issues'

setup(
author='René-Marc Simard',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _setup_mock_server(mocked: aioresponses) -> None:

:param mocked: aiohttp response
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = "IT IS 1 MINUTE TO MIDNIGHT"
mocked.get(
Expand Down Expand Up @@ -119,7 +119,7 @@ async def test_cli_request_version(capsys: CaptureFixture) -> None:

assert exception.type == SystemExit
assert exception.value.code == 0
assert "countdoom {}".format(countdoom.__version__) in output[0]
assert f"countdoom {countdoom.__version__}" in output[0]


@pytest.mark.asyncio
Expand Down Expand Up @@ -271,7 +271,7 @@ async def test_cli_request_internal_error(capsys: CaptureFixture) -> None:
:param capsys: System-level capture fixture
"""
with aioresponses() as mocked:
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = ' '
mocked.get(
Expand Down
51 changes: 24 additions & 27 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def response() -> Response:

:return: Request response
"""
return requests.get(CountdoomClient.CLOCK_URL)
return requests.get(CountdoomClient.CLOCK_URL, timeout=5)


def _get_path(string: str) -> str:
Expand All @@ -142,16 +142,13 @@ def _setup_servers(httpserver: HTTPServer) -> None:

:param httpserver: HTTP Server
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'

sentences = SENTENCES_VALID + SENTENCES_INVALID
# sentences = SENTENCES_VALID
# for sentence in SENTENCES_INVALID:
# sentences.append(sentence)
for sentence in sentences:
path = _get_path(sentence[0])
httpserver.expect_request('/{}'.format(path)).respond_with_data(
httpserver.expect_request(f'/{path}').respond_with_data(
prefix + sentence[0] + suffix
)

Expand Down Expand Up @@ -197,7 +194,7 @@ async def test_valid_sentence(httpserver: HTTPServer, sentence: str) -> None:

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -223,7 +220,7 @@ async def test_valid_countdown(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -249,7 +246,7 @@ async def test_valid_minutes(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -275,7 +272,7 @@ async def test_valid_clock(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -302,7 +299,7 @@ async def test_valid_time(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -329,7 +326,7 @@ async def test_invalid_minutes(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
with pytest.raises(CountdoomClientError) as err:
await client.fetch_data()
Expand All @@ -356,7 +353,7 @@ async def test_invalid_clock(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
with pytest.raises(CountdoomClientError) as err:
await client.fetch_data()
Expand All @@ -383,7 +380,7 @@ async def test_invalid_time(

client = CountdoomClient()
path = _get_path(sentence)
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
with pytest.raises(CountdoomClientError) as err:
await client.fetch_data()
Expand All @@ -399,16 +396,16 @@ async def test_invalid_selector(httpserver: HTTPServer) -> None:

:param httpserver: HTTP Server
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = "IT IS 1 AND A HALF MINUTE TO MIDNIGHT"
path = 'test_invalid_selector'
httpserver.expect_request('/{}'.format(path)).respond_with_data(
httpserver.expect_request(f'/{path}').respond_with_data(
prefix + string + suffix
)

client = CountdoomClient()
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
selector = '.wrong-id-' + str(random.randint(0, 100000000))
setattr(client, 'CLOCK_URL', clock_url)
setattr(client, 'SELECTOR', selector)
Expand All @@ -425,16 +422,16 @@ async def test_htmlized_sentence(httpserver: HTTPServer) -> None:

:param httpserver: HTTP Server
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = " IT IS <em>STILL</em> 1 <b>MINUTE</b> TO MIDNIGHT"
path = 'test_htmlized_sentence'
httpserver.expect_request('/{}'.format(path)).respond_with_data(
httpserver.expect_request(f'/{path}').respond_with_data(
prefix + string + suffix
)

client = CountdoomClient()
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -450,16 +447,16 @@ async def test_empty_sentence(httpserver: HTTPServer) -> None:

:param httpserver: HTTP Server
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = ' '
path = 'test_empty_sentence'
httpserver.expect_request('/{}'.format(path)).respond_with_data(
httpserver.expect_request(f'/{path}').respond_with_data(
prefix + string + suffix
)

client = CountdoomClient()
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
with pytest.raises(CountdoomClientError) as err:
await client.fetch_data()
Expand Down Expand Up @@ -500,16 +497,16 @@ async def test_formatted_time(httpserver: HTTPServer) -> None:

:param httpserver: HTTP Server
"""
prefix = '<h3 class="{}">'.format(CountdoomClient.SELECTOR[1:])
prefix = f'<h3 class="{CountdoomClient.SELECTOR[1:]}">'
suffix = '</h3>'
string = "IT IS 16 MINUTES TO MIDNIGHT"
path = 'test_formatted_time'
httpserver.expect_request('/{}'.format(path)).respond_with_data(
httpserver.expect_request(f'/{path}').respond_with_data(
prefix + string + suffix
)

client = CountdoomClient()
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
data = await client.fetch_data()

Expand All @@ -526,7 +523,7 @@ async def test_url_not_found(httpserver: HTTPServer) -> None:
"""
path = 'test_url_not_found'
client = CountdoomClient()
clock_url = httpserver.url_for('/{}'.format(path))
clock_url = httpserver.url_for(f'/{path}')
setattr(client, 'CLOCK_URL', clock_url)
with pytest.raises(CountdoomClientError) as err:
await client.fetch_data()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_package_main() -> None:
This check uses a subprocess to validate the package, since the
package's __main__.py cannot be imported for tests.
"""
process = subprocess.Popen(
with subprocess.Popen(
['python', '-m', 'countdoom', '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout = process.communicate()[0]
) as process:
stdout = process.communicate()[0]

assert 'countdoom {}'.format(countdoom.__version__) in str(stdout)
assert f'countdoom {countdoom.__version__}' in str(stdout)
Loading