Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ test.types:

.PHONY: test.unit
test.unit:
poetry run pytest --verbose
poetry run python -m unittest discover -v
83 changes: 2 additions & 81 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ utt = "utt.__main__:main"

[tool.poetry.group.dev.dependencies]
black = "^23.12.1"
ddt = "^1.7.1"
flake8 = "^7.0.0"
isort = "^5.13.2"
pyright = "^1.1.407"
pytest = "^7.4.4"
requests = "^2.31.0"
setuptools = "^80.9.0"
Empty file added test/unit/report/__init__.py
Empty file.
21 changes: 10 additions & 11 deletions test/unit/report/test_formatter.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import unittest
from datetime import timedelta

from utt.report.formatter import format_duration


def test_formatter_less_than_a_minute():
assert format_duration(timedelta(seconds=10)) == "0h00"
class TestFormatter(unittest.TestCase):
def test_formatter_less_than_a_minute(self):
self.assertEqual(format_duration(timedelta(seconds=10)), "0h00")

def test_formatter_less_than_a_hour(self):
self.assertEqual(format_duration(timedelta(minutes=8, seconds=45)), "0h08")

def test_formatter_less_than_a_hour():
assert format_duration(timedelta(minutes=8, seconds=45)) == "0h08"
def test_formatter_less_than_a_day(self):
self.assertEqual(format_duration(timedelta(hours=8, minutes=20)), "8h20")


def test_formatter_less_than_a_day():
assert format_duration(timedelta(hours=8, minutes=20)) == "8h20"


def test_formatter_more_than_a_day():
assert format_duration(timedelta(days=1, hours=2, minutes=20)) == "26h20"
def test_formatter_more_than_a_day(self):
self.assertEqual(format_duration(timedelta(days=1, hours=2, minutes=20)), "26h20")
36 changes: 16 additions & 20 deletions test/unit/test_entry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import unittest

import ddt

from utt.components.entry_parser import EntryParser

VALID_ENTRIES = [
Expand Down Expand Up @@ -60,26 +58,24 @@
]


@ddt.ddt
class ValidEntry(unittest.TestCase):
@ddt.data(*VALID_ENTRIES)
@ddt.unpack
def test(self, name, expected_datetime, expected_name, expected_comment):
entry_parser = EntryParser()
entry = entry_parser.parse(name)
if entry is None:
self.fail("EntryParser returned None for valid entry")
def test_valid_entries(self):
for test_case in VALID_ENTRIES:
with self.subTest(name=test_case["name"]):
entry_parser = EntryParser()
entry = entry_parser.parse(test_case["name"])
if entry is None:
self.fail("EntryParser returned None for valid entry")

self.assertEqual(entry.datetime, expected_datetime)
self.assertEqual(entry.name, expected_name)
self.assertEqual(entry.comment, expected_comment)
self.assertEqual(entry.datetime, test_case["expected_datetime"])
self.assertEqual(entry.name, test_case["expected_name"])
self.assertEqual(entry.comment, test_case["expected_comment"])


@ddt.ddt
class InvalidEntry(unittest.TestCase):
@ddt.data(*INVALID_ENTRIES)
@ddt.unpack
def test(self, text):
entry_parser = EntryParser()
entry = entry_parser.parse(text)
self.assertIsNone(entry)
def test_invalid_entries(self):
for test_case in INVALID_ENTRIES:
with self.subTest(text=test_case[0]):
entry_parser = EntryParser()
entry = entry_parser.parse(test_case[0])
self.assertIsNone(entry)
14 changes: 6 additions & 8 deletions test/unit/test_parse_date.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import unittest

import ddt

from utt.components.report_args import parse_date

VALID_ENTRIES = [
Expand All @@ -24,10 +22,10 @@
]


@ddt.ddt
class ParseDate(unittest.TestCase):
@ddt.data(*VALID_ENTRIES)
@ddt.unpack
def test(self, report_date, today, expected_report_date, is_past):
actual_report_date = parse_date(today, report_date, is_past)
self.assertEqual(actual_report_date, expected_report_date)
def test_parse_date(self):
for test_case in VALID_ENTRIES:
report_date, today, expected_report_date, is_past = test_case
with self.subTest(report_date=report_date, today=today, is_past=is_past):
actual_report_date = parse_date(today, report_date, is_past)
self.assertEqual(actual_report_date, expected_report_date)
80 changes: 40 additions & 40 deletions test/unit/test_report.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import datetime

import pytest
import unittest

from utt.report.common import timedelta_to_billable

TEST_CASES = [
(dict(minutes=0), " 0.0"),
(dict(minutes=1), " 0.0"),
(dict(minutes=2), " 0.0"),
(dict(minutes=3), " 0.1"),
(dict(minutes=4), " 0.1"),
(dict(minutes=5), " 0.1"),
(dict(minutes=6), " 0.1"),
(dict(minutes=7), " 0.1"),
(dict(minutes=8), " 0.1"),
(dict(minutes=9), " 0.2"),
(dict(minutes=14), " 0.2"),
(dict(minutes=15), " 0.3"),
(dict(minutes=30), " 0.5"),
(dict(minutes=56), " 0.9"),
(dict(minutes=57), " 1.0"),
(dict(minutes=60), " 1.0"),
(dict(minutes=62), " 1.0"),
(dict(minutes=63), " 1.1"),
(dict(minutes=66), " 1.1"),
# NOTE, utt doesn't really deal with seconds, but this is how the
# rounding would work if it did.
(dict(seconds=1), " 0.0"),
(dict(seconds=179), " 0.0"),
(dict(seconds=180), " 0.1"),
(dict(seconds=181), " 0.1"),
(dict(seconds=359), " 0.1"),
(dict(seconds=360), " 0.1"),
(dict(seconds=361), " 0.1"),
]


@pytest.mark.parametrize(
"delta,billable",
[
(dict(minutes=0), " 0.0"),
(dict(minutes=1), " 0.0"),
(dict(minutes=2), " 0.0"),
(dict(minutes=3), " 0.1"),
(dict(minutes=4), " 0.1"),
(dict(minutes=5), " 0.1"),
(dict(minutes=6), " 0.1"),
(dict(minutes=7), " 0.1"),
(dict(minutes=8), " 0.1"),
(dict(minutes=9), " 0.2"),
(dict(minutes=14), " 0.2"),
(dict(minutes=15), " 0.3"),
(dict(minutes=30), " 0.5"),
(dict(minutes=56), " 0.9"),
(dict(minutes=57), " 1.0"),
(dict(minutes=60), " 1.0"),
(dict(minutes=62), " 1.0"),
(dict(minutes=63), " 1.1"),
(dict(minutes=66), " 1.1"),
# NOTE, utt doesn't really deal with seconds, but this is how the
# rounding would work if it did.
(dict(seconds=1), " 0.0"),
(dict(seconds=179), " 0.0"),
(dict(seconds=180), " 0.1"),
(dict(seconds=181), " 0.1"),
(dict(seconds=359), " 0.1"),
(dict(seconds=360), " 0.1"),
(dict(seconds=361), " 0.1"),
],
)
def test_timedelta_to_billable(delta, billable):
"""Ensure that _timedelta_to_billable gives intended outcome.
class TestTimedeltaToBillable(unittest.TestCase):
def test_timedelta_to_billable(self):
"""Ensure that _timedelta_to_billable gives intended outcome.

Hours are divided in 10, and we round up to the next "6 minute unit".
"""
assert timedelta_to_billable(datetime.timedelta(**delta)) == billable
Hours are divided in 10, and we round up to the next "6 minute unit".
"""
for delta, billable in TEST_CASES:
with self.subTest(delta=delta, billable=billable):
self.assertEqual(timedelta_to_billable(datetime.timedelta(**delta)), billable)