Skip to content

Commit

Permalink
Strict typing and link issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 26, 2024
1 parent 656da89 commit e94732f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions jaraco/pmxbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from pmxbot.core import command


@command("resolv", doc="resolve a hostname")
def resolve(rest):
@command("resolv", doc="resolve a hostname") # type: ignore[misc] # pmxbot/pmxbot#113
def resolve(rest: str) -> str:
"""
>>> resolve("localhost")
'...'
Expand Down
18 changes: 10 additions & 8 deletions jaraco/pmxbot/notification.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

import re

import twilio.rest

import pmxbot
from pmxbot.core import command


from_number = '+15712573984'


@command()
def send_text(rest):
@command() # type: ignore[misc] # pmxbot/pmxbot#113
def send_text(rest: str) -> str | None:
"""
Send an SMS message: pass the phone number and message to send.
"""
Expand All @@ -18,17 +20,17 @@ def send_text(rest):
number, _, msg = rest.partition(' ')
number = parse_number(number)
if not msg:
return
msg = msg.encode('ascii')[:160]
return None
encoded_msg = msg.encode('ascii')[:160]
client = twilio.rest.Client(username=account, password=token)
client.messages.create(to=number, from_=from_number, body=msg)
client.messages.create(to=number, from_=from_number, body=encoded_msg)
return "Sent {count} chars to {number}".format(
count=len(msg),
count=len(encoded_msg),
number=number,
)


def parse_number(input_):
def parse_number(input_: str) -> str:
"""
Strip everything but digits and + sign; ensure it begins with a country
code.
Expand Down
Empty file added jaraco/pmxbot/py.typed
Empty file.
10 changes: 9 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[mypy]
# Is the project well-typed?
strict = False
strict = True

# Early opt-in even when strict = False
warn_unused_ignores = True
Expand All @@ -12,3 +12,11 @@ explicit_package_bases = True

# Disable overload-overlap due to many false-positives
disable_error_code = overload-overlap

# pmxbot/pmxbot#113
[mypy-pmxbot.*]
ignore_missing_imports = True

# twilio/twilio-python#568
[mypy-twilio.*]
ignore_missing_imports = True
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,3 @@ notification = "jaraco.pmxbot.notification"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143
16 changes: 10 additions & 6 deletions tests/test_notification.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import pytest
from typing import Dict

import pmxbot
from jaraco.collections import ItemsAsAttributes
import pytest

from jaraco.collections import ItemsAsAttributes
from jaraco.pmxbot import notification


@pytest.fixture
def twilio_test_credentials(monkeypatch):
class ConfigDict(ItemsAsAttributes, dict):
def twilio_test_credentials(monkeypatch: pytest.MonkeyPatch) -> None:
class ConfigDict(ItemsAsAttributes, Dict[str, str]):
pass

monkeypatch.setattr(pmxbot, 'config', ConfigDict(), raising=False)
Expand All @@ -24,10 +26,12 @@ class ConfigDict(ItemsAsAttributes, dict):
monkeypatch.setattr(notification, 'from_number', '+15005550006')


def test_send_text(twilio_test_credentials):
@pytest.mark.usefixtures("twilio_test_credentials")
def test_send_text() -> None:
res = notification.send_text(rest='+12026837967 <3 pmxbot')
assert res == 'Sent 9 chars to +12026837967'


def test_no_message(twilio_test_credentials):
@pytest.mark.usefixtures("twilio_test_credentials")
def test_no_message() -> None:
assert not notification.send_text(rest='')

0 comments on commit e94732f

Please sign in to comment.