From 5e57d6a80570fb00d784c98dac815bb2a3e5d3a8 Mon Sep 17 00:00:00 2001 From: Mathieu Larose Date: Tue, 4 Nov 2025 08:04:39 -0500 Subject: [PATCH] Remove pytest --- Makefile | 2 +- poetry.lock | 83 +----------------------------- pyproject.toml | 2 - test/unit/report/__init__.py | 0 test/unit/report/test_formatter.py | 21 ++++---- test/unit/test_entry.py | 36 ++++++------- test/unit/test_parse_date.py | 14 +++-- test/unit/test_report.py | 80 ++++++++++++++-------------- 8 files changed, 75 insertions(+), 163 deletions(-) create mode 100644 test/unit/report/__init__.py diff --git a/Makefile b/Makefile index 902a94b..fc90e85 100644 --- a/Makefile +++ b/Makefile @@ -83,4 +83,4 @@ test.types: .PHONY: test.unit test.unit: - poetry run pytest --verbose + poetry run python -m unittest discover -v diff --git a/poetry.lock b/poetry.lock index 71578dc..eb9ff98 100644 --- a/poetry.lock +++ b/poetry.lock @@ -208,40 +208,12 @@ description = "Cross-platform colored terminal text." optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" groups = ["dev"] -markers = "platform_system == \"Windows\" or sys_platform == \"win32\"" +markers = "platform_system == \"Windows\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] -[[package]] -name = "ddt" -version = "1.7.1" -description = "Data-Driven/Decorated Tests" -optional = false -python-versions = "*" -groups = ["dev"] -files = [ - {file = "ddt-1.7.1-py2.py3-none-any.whl", hash = "sha256:2c4ac421bbdc10d2403b472294500c6f75ca822386c34d9fe82882d7a2ce9682"}, - {file = "ddt-1.7.1.tar.gz", hash = "sha256:1a4472c477bf766f75f7b1efb628656ff3c35ff3f6c821129ae8e328fff8a9a2"}, -] - -[[package]] -name = "exceptiongroup" -version = "1.2.0" -description = "Backport of PEP 654 (exception groups)" -optional = false -python-versions = ">=3.7" -groups = ["dev"] -markers = "python_version == \"3.10\"" -files = [ - {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, - {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, -] - -[package.extras] -test = ["pytest (>=6)"] - [[package]] name = "flake8" version = "7.0.0" @@ -271,18 +243,6 @@ files = [ {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, ] -[[package]] -name = "iniconfig" -version = "2.0.0" -description = "brain-dead simple config-ini parsing" -optional = false -python-versions = ">=3.7" -groups = ["dev"] -files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, -] - [[package]] name = "isort" version = "5.13.2" @@ -374,22 +334,6 @@ files = [ docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] -[[package]] -name = "pluggy" -version = "1.3.0" -description = "plugin and hook calling mechanisms for python" -optional = false -python-versions = ">=3.8" -groups = ["dev"] -files = [ - {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, - {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, -] - -[package.extras] -dev = ["pre-commit", "tox"] -testing = ["pytest", "pytest-benchmark"] - [[package]] name = "pycodestyle" version = "2.11.1" @@ -435,29 +379,6 @@ all = ["nodejs-wheel-binaries", "twine (>=3.4.1)"] dev = ["twine (>=3.4.1)"] nodejs = ["nodejs-wheel-binaries"] -[[package]] -name = "pytest" -version = "7.4.4" -description = "pytest: simple powerful testing with Python" -optional = false -python-versions = ">=3.7" -groups = ["dev"] -files = [ - {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"}, - {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"}, -] - -[package.dependencies] -colorama = {version = "*", markers = "sys_platform == \"win32\""} -exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} -iniconfig = "*" -packaging = "*" -pluggy = ">=0.12,<2.0" -tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} - -[package.extras] -testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] - [[package]] name = "requests" version = "2.31.0" @@ -546,4 +467,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" python-versions = "^3.10" -content-hash = "4982f99a2271f4be000bd7bfe753330690c6a760fb443d24fd07693874eaddc5" +content-hash = "655204fe7f2562249e0fdedceb79303d45f0765d21b1b9389ac4b5b7992b433e" diff --git a/pyproject.toml b/pyproject.toml index 34c9c0a..8ffcf89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/test/unit/report/__init__.py b/test/unit/report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/unit/report/test_formatter.py b/test/unit/report/test_formatter.py index 5eae6c2..7078b2b 100644 --- a/test/unit/report/test_formatter.py +++ b/test/unit/report/test_formatter.py @@ -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") diff --git a/test/unit/test_entry.py b/test/unit/test_entry.py index 6e8e389..a6a26e9 100644 --- a/test/unit/test_entry.py +++ b/test/unit/test_entry.py @@ -1,8 +1,6 @@ import datetime import unittest -import ddt - from utt.components.entry_parser import EntryParser VALID_ENTRIES = [ @@ -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) diff --git a/test/unit/test_parse_date.py b/test/unit/test_parse_date.py index afe4182..7a34a89 100644 --- a/test/unit/test_parse_date.py +++ b/test/unit/test_parse_date.py @@ -1,8 +1,6 @@ import datetime import unittest -import ddt - from utt.components.report_args import parse_date VALID_ENTRIES = [ @@ -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) diff --git a/test/unit/test_report.py b/test/unit/test_report.py index c3996ab..612d794 100644 --- a/test/unit/test_report.py +++ b/test/unit/test_report.py @@ -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)