Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes parse error when date is only spaces #6

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Unit Testing

on:
pull_request:
branches:
- master

jobs:
unti_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements_test.txt -r requirements.txt
pip install -e .
- name: Run unit tests
run: python -m pytest --import-mode=append tests/
2 changes: 1 addition & 1 deletion pyplaato/models/keg.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __repr__(self):

@property
def date(self) -> float:
if self.__date is not None and self.__date:
if self.__date is not None and self.__date and not self.__date.isspace():
date = dateutil.parser.parse(self.__date)
return date.timestamp()
return super().date
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aiohttp==3.7.4
aiohttp==3.8.1
python-dateutil==2.8.1
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest==7.0.1
pytest==7.0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/JohNan/pyplaato",
packages=setuptools.find_packages(exclude=["tests","tests.*"]),
packages=setuptools.find_packages(exclude=["tests", "tests.*"]),
classifiers=[
"Framework :: AsyncIO",
"Programming Language :: Python :: 3",
Expand Down
27 changes: 25 additions & 2 deletions tests/models/test_keg.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import os, time
from datetime import datetime
from unittest import mock

from pyplaato.models.keg import PlaatoKeg


def setup_module(module):
os.environ['TZ'] = 'Europe/London'
time.tzset()


def test_date_prop_with_value_returns_its_timestamp():
pins = PlaatoKeg.Pins
keg = PlaatoKeg({pins.DATE: "1/1/2022"})
assert 1641024000.0 == keg.date
keg = PlaatoKeg({pins.DATE: "10/1/2022"})
assert 1664578800.0 == keg.date


@mock.patch("pyplaato.models.device.datetime")
Expand All @@ -17,3 +23,20 @@ def test_date_prop_with_no_value_returns_current_timestamp(m_datetime):
keg = PlaatoKeg({})
assert now.timestamp() == keg.date


@mock.patch("pyplaato.models.device.datetime")
def test_date_prop_with_empty_string(m_datetime):
now = datetime(2022, 10, 1)
m_datetime.now.return_value = now
pins = PlaatoKeg.Pins
keg = PlaatoKeg({pins.DATE: ""})
assert now.timestamp() == keg.date


@mock.patch("pyplaato.models.device.datetime")
def test_date_prop_with_space_string(m_datetime):
now = datetime(2022, 10, 1)
m_datetime.now.return_value = now
pins = PlaatoKeg.Pins
keg = PlaatoKeg({pins.DATE: " "})
assert now.timestamp() == keg.date