Procházet zdrojové kódy

Alle Tests konvertiert zu pytest

gc-server3 před 6 dny
rodič
revize
450ada0475

+ 2 - 2
.vscode/settings.json

@@ -8,8 +8,8 @@
     },
     "isort.args":["--profile", "black"],
     "black-formatter.args": ["--line-length", "120"],
-    "python.testing.pytestEnabled": false,
-    "python.testing.unittestEnabled": true,
+    "python.testing.pytestEnabled": true,
+    "python.testing.unittestEnabled": false,
     "files.associations": {
         "*.mac": "vbs"
     },

+ 11 - 15
datev/export_extf.py

@@ -314,23 +314,19 @@ def calculate_sha256(data) -> str:
 
 
 def test_content():
-    print(
-        extf_files_equal_content(
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
-        )
+    assert extf_files_equal_content(
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
     )
-    print(
-        extf_files_equal_content(
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240222_155629.csv",
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
-        )
+
+    assert extf_files_equal_content(
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240222_155629.csv",
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
     )
-    print(
-        extf_files_equal_content(
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
-            "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240515_104021.csv",
-        )
+
+    assert extf_files_equal_content(
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240514_112734.csv",
+        "datev/export/EXTF_Buchungsstapel_30612_10139_202312_20240515_104021.csv",
     )
 
 

+ 32 - 32
gchr/tests/test_gchr.py

@@ -1,39 +1,39 @@
-import unittest
-
 import pandas as pd
 
 from gchr.gchr import GCHR
 from gchr.gchr_bookings import GchrBookings
 from gchr.gchr_translate import TRANSLATE
 
+base_dir_1: str = "C:\\Projekte\\GCHR2_Testdaten\\Kunden\\Altermann"
+base_dir_2: str = "C:\\Projekte\\GCHR2_Testdaten\\Kunden\\Koenig-und-Partner"
+
+
+def test_single_booking_files():
+    gchr = GCHR(base_dir_1)
+    assert isinstance(gchr.bookings, GchrBookings)
+    assert len(gchr.bookings.account_bookings) == 1
+    assert gchr.bookings.account_bookings[0].name == "GuV_Bilanz_Salden.csv"
+
+
+def test_multiple_booking_files():
+    gchr = GCHR(base_dir_2)
+    assert isinstance(gchr.bookings, GchrBookings)
+    assert len(gchr.bookings.account_bookings) == 2
+    assert gchr.bookings.account_bookings[0].name == "GuV_Bilanz_Salden.csv"
+    assert gchr.bookings.account_bookings[1].name == "GuV_Bilanz_Salden_deop03.csv"
+
+
+def test_translation_existing():
+    gchr = GCHR(base_dir_1)
+    df = gchr.df_translate
+    assert isinstance(df, pd.DataFrame)
+    assert df.shape[1] == 12
+    assert list(df.columns) == TRANSLATE
+    assert df.shape[0] > 0, "Translation not empty"
+
 
-class TestGchr(unittest.TestCase):
-    base_dir_1: str = "C:\\Projekte\\GCHR2_Testdaten\\Kunden\\Altermann"
-    base_dir_2: str = "C:\\Projekte\\GCHR2_Testdaten\\Kunden\\Koenig-und-Partner"
-
-    def test_single_booking_files(self):
-        gchr = GCHR(self.base_dir_1)
-        self.assertIsInstance(gchr.bookings, GchrBookings)
-        self.assertEqual(len(gchr.bookings.account_bookings), 1)
-        self.assertEqual(gchr.bookings.account_bookings[0].name, "GuV_Bilanz_Salden.csv")
-
-    def test_multiple_booking_files(self):
-        gchr = GCHR(self.base_dir_2)
-        self.assertIsInstance(gchr.bookings, GchrBookings)
-        self.assertEqual(len(gchr.bookings.account_bookings), 2)
-        self.assertEqual(gchr.bookings.account_bookings[0].name, "GuV_Bilanz_Salden.csv")
-        self.assertEqual(gchr.bookings.account_bookings[1].name, "GuV_Bilanz_Salden_deop03.csv")
-
-    def test_translation_existing(self):
-        gchr = GCHR(self.base_dir_1)
-        df = gchr.df_translate
-        self.assertIsInstance(df, pd.DataFrame)
-        self.assertEqual(df.shape[1], 12)
-        self.assertListEqual(list(df.columns), TRANSLATE)
-        self.assertGreater(df.shape[0], 0, "Translation not empty")
-
-    def test_all_periods(self):
-        periods = GCHR.get_all_periods("2024-12-23")
-        self.assertEqual(len(periods), 12)
-        self.assertEqual(periods[0], ("2023", "12"))
-        self.assertEqual(periods[-1], ("2024", "11"))
+def test_all_periods():
+    periods = GCHR.get_all_periods("2024-12-23")
+    assert len(periods) == 12
+    assert periods[0] == ("2023", "12")
+    assert periods[-1] == ("2024", "11")

+ 1 - 0
pyproject.toml

@@ -26,6 +26,7 @@ dependencies = [
     "pyinstaller>=6.14.1",
     "pymysql>=1.1.1",
     "pyodbc>=5.2.0",
+    "pytest>=9.0.2",
     "python-crontab>=3.2.0",
     "python-dateutil>=2.9.0.post0",
     "requests>=2.32.3",

+ 2 - 0
sandbox/access.py

@@ -1,6 +1,8 @@
 import codecs
 import sys
 
+# verschoben nach gctools/misc/access_tools.py
+
 
 def crack_access_mdb(file):
     no_pass_62 = "0C"

+ 6 - 14
sandbox/gilded_rose/test_gilded_rose.py

@@ -1,16 +1,8 @@
-# -*- coding: utf-8 -*-
-import unittest
+from gilded_rose import GildedRose, Item
 
-from gilded_rose import Item, GildedRose
 
-
-class GildedRoseTest(unittest.TestCase):
-    def test_foo(self):
-        items = [Item("foo", 0, 0)]
-        gilded_rose = GildedRose(items)
-        gilded_rose.update_quality()
-        self.assertEquals("fixme", items[0].name)
-
-        
-if __name__ == '__main__':
-    unittest.main()
+def test_foo():
+    items = [Item("foo", 0, 0)]
+    gilded_rose = GildedRose(items)
+    gilded_rose.update_quality()
+    assert "fixme" == items[0].name

+ 5 - 12
sandbox/test_ohno.py

@@ -1,15 +1,8 @@
-import unittest
-
 from sandbox import ohno
 
 
-class test_ohno(unittest.TestCase):
-    def test_simple(self):
-        board = ohno.Board(4)
-        board.set_initial([[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]])
-        solved = board.solve()
-        self.assertEqual(len(solved), 1)
-
-
-if __name__ == "__main__":
-    unittest.main()
+def test_simple():
+    board = ohno.Board(4)
+    board.set_initial([[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]])
+    solved = board.solve()
+    assert len(solved) == 1

+ 39 - 35
sandbox/test_relationship.py

@@ -1,5 +1,3 @@
-import unittest
-
 from sandbox import relationship
 
 relations_first_grade_female = [
@@ -157,49 +155,55 @@ burghard_freya = [("Freya", "1.4.6.3.4.3", "w", "Tochter", "Harald", "1.4.6.3.4"
 burghard_all = [("Harald", "1.4.6.3.4", "m", "ich", "Harald", "1.4.6.3.4", "m", "ich", 0)]
 
 
-class test_relatives(unittest.TestCase):
-    def test_first_grade_female(self):
-        self.relations(relations_first_grade_female)
+def relations(relations_list):
+    for rel, title in relations_list:
+        result = relationship.relationship_name(*rel)
+        assert result == title
+
+
+def test_first_grade_female():
+    relations(relations_first_grade_female)
+
+
+def test_second_grade_female():
+    relations(relations_second_grade_female)
+
+
+def test_higher_grade_female():
+    relations(relations_higher_grade_female)
+
+
+def test_special_grade_female():
+    relations(relations_special_grade_female)
+
 
-    def test_second_grade_female(self):
-        self.relations(relations_second_grade_female)
+def test_first_grade_male():
+    relations(relations_first_grade_male)
 
-    def test_higher_grade_female(self):
-        self.relations(relations_higher_grade_female)
 
-    def test_special_grade_female(self):
-        self.relations(relations_special_grade_female)
+def test_second_grade_male():
+    relations(relations_second_grade_male)
 
-    def test_first_grade_male(self):
-        self.relations(relations_first_grade_male)
 
-    def test_second_grade_male(self):
-        self.relations(relations_second_grade_male)
+def test_higher_grade_male():
+    relations(relations_higher_grade_male)
 
-    def test_higher_grade_male(self):
-        self.relations(relations_higher_grade_male)
 
-    def test_special_grade_male(self):
-        self.relations(relations_special_grade_male)
+def test_special_grade_male():
+    relations(relations_special_grade_male)
 
-    def relations(self, relations_list):
-        for rel, title in relations_list:
-            result = relationship.relationship_name(*rel)
-            self.assertEqual(result, title)
 
-    def test_distance(self):
-        for rel, title, distance in relations_higher_grade_distance:
-            result = relationship.relationship_distance(rel[0], rel[1])
-            self.assertEqual(result, distance, title)
+def test_distance():
+    for rel, title, distance in relations_higher_grade_distance:
+        result = relationship.relationship_distance(rel[0], rel[1])
+        assert result == distance, title
 
-    def test_relations_list(self):
-        result = relationship.relationship_list(burghard, 5)
-        self.assertEqual(result[0], burghard_freya[0])
 
-    def test_relations_list_all(self):
-        result = relationship.relationship_list_all(burghard)
-        self.assertEqual(result[0], burghard_all[0])
+def test_relations_list():
+    result = relationship.relationship_list(burghard, 5)
+    assert result[0] == burghard_freya[0]
 
 
-if __name__ == "__main__":
-    unittest.main()
+def test_relations_list_all():
+    result = relationship.relationship_list_all(burghard)
+    assert result[0] == burghard_all[0]

+ 70 - 72
sandbox/test_sudoku_solver.py

@@ -1,5 +1,3 @@
-import unittest
-
 from sandbox import sudoku_solver
 
 board_1 = [
@@ -77,73 +75,73 @@ solution_3 = [
 empty = ["." * 9 for i in range(9)]
 
 
-class test_sudoku_solver(unittest.TestCase):
-    def test_simple(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        row = board.get_row(0)
-        self.assertEqual(row, board_1[0])
-        col = board.get_col(0)
-        self.assertEqual(col, "..5.7....")
-        block = board.get_block(0, 0)
-        self.assertEqual(block, [".1.", "...", "54."])
-        block = board.get_block(4, 6)
-        self.assertEqual(block, ["95.", "1.4", "2.."])
-
-    def test_simple_set(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        board.set_cell(5, 7, "6")
-        row = board.get_row(5)
-        self.assertEqual(row, ".89...26.")
-
-    def test_possibilities(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        p = board.get_possibilities(1, 4)
-        self.assertEqual(p, {"1", "4", "5"})
-
-    def test_all_possibilities(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        p = board.get_all_possibilities()
-        self.assertEqual(p[1][4], {"1", "4", "5"})
-
-    def test_unique_cell(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        solving_steps = [
-            (5, 7, "6"),
-            (4, 7, "8"),
-            (4, 5, "9"),
-            (2, 5, "1"),
-            (2, 3, "9"),
-            (2, 7, "2"),
-            (6, 5, "4"),
-            (0, 5, "5"),
-            (1, 4, "4"),
-        ]
-        for x, y, v in solving_steps:
-            cell = board.get_unique_cell()
-            self.assertEqual(cell, (x, y))
-            board.set_cell(x, y, v)
-
-    def test_solve(self):
-        board = sudoku_solver.Board()
-        board.set_initial(board_2)
-        b = board.solve()
-        self.assertEqual(b, solution_2)
-
-        board = sudoku_solver.Board()
-        board.set_initial(board_1)
-        b = board.solve()
-        self.assertEqual(b, solution_1)
-
-        board = sudoku_solver.Board()
-        board.set_initial(board_3)
-        b = board.solve()
-        self.assertEqual(b, solution_3)
-
-
-if __name__ == "__main__":
-    unittest.main()
+def test_simple():
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    row = board.get_row(0)
+    assert row == board_1[0]
+    col = board.get_col(0)
+    assert col == "..5.7...."
+    block = board.get_block(0, 0)
+    assert block == [".1.", "...", "54."]
+    block = board.get_block(4, 6)
+    assert block == ["95.", "1.4", "2.."]
+
+
+def test_simple_set():
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    board.set_cell(5, 7, "6")
+    row = board.get_row(5)
+    assert row == ".89...26."
+
+
+def test_possibilities():
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    p = board.get_possibilities(1, 4)
+    assert p == {"1", "4", "5"}
+
+
+def test_all_possibilities():
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    p = board.get_all_possibilities()
+    assert p[1][4] == {"1", "4", "5"}
+
+
+def test_unique_cell():
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    solving_steps = [
+        (5, 7, "6"),
+        (4, 7, "8"),
+        (4, 5, "9"),
+        (2, 5, "1"),
+        (2, 3, "9"),
+        (2, 7, "2"),
+        (6, 5, "4"),
+        (0, 5, "5"),
+        (1, 4, "4"),
+    ]
+    for x, y, v in solving_steps:
+        cell = board.get_unique_cell()
+        assert cell == (x, y)
+        board.set_cell(x, y, v)
+
+
+def test_solve():
+    board = sudoku_solver.Board()
+    board.set_initial(board_2)
+    b = board.solve()
+    assert b == solution_2
+
+    board = sudoku_solver.Board()
+    board.set_initial(board_1)
+    b = board.solve()
+    assert b == solution_1
+
+    board = sudoku_solver.Board()
+    board.set_initial(board_3)
+    b = board.solve()
+    assert b == solution_3

+ 36 - 0
uv.lock

@@ -307,6 +307,15 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/54/22/0ba0bc50f52033ef00c83c276c4ab85810a8d0d74bcf27ac83324aa8daba/imap_tools-1.10.0-py3-none-any.whl", hash = "sha256:8b8794f0ffe4b3de1e72dea4e0b77ed744d9cd225ecaace81976a599eec0947b", size = 34655 },
 ]
 
+[[package]]
+name = "iniconfig"
+version = "2.3.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503 }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484 },
+]
+
 [[package]]
 name = "itsdangerous"
 version = "2.2.0"
@@ -618,6 +627,15 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/fe/39/979e8e21520d4e47a0bbe349e2713c0aac6f3d853d0e5b34d76206c439aa/platformdirs-4.3.8-py3-none-any.whl", hash = "sha256:ff7059bb7eb1179e2685604f4aaf157cfd9535242bd23742eadc3c13542139b4", size = 18567 },
 ]
 
+[[package]]
+name = "pluggy"
+version = "1.6.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412 }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538 },
+]
+
 [[package]]
 name = "psutil"
 version = "7.0.0"
@@ -819,6 +837,22 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/e1/6b/2706497c86e8d69fb76afe5ea857fe1794621aa0f3b1d863feb953fe0f22/pypdfium2-4.30.1-py3-none-win_arm64.whl", hash = "sha256:c2b6d63f6d425d9416c08d2511822b54b8e3ac38e639fc41164b1d75584b3a8c", size = 2814810 },
 ]
 
+[[package]]
+name = "pytest"
+version = "9.0.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+    { name = "colorama", marker = "sys_platform == 'win32'" },
+    { name = "iniconfig" },
+    { name = "packaging" },
+    { name = "pluggy" },
+    { name = "pygments" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/d1/db/7ef3487e0fb0049ddb5ce41d3a49c235bf9ad299b6a25d5780a89f19230f/pytest-9.0.2.tar.gz", hash = "sha256:75186651a92bd89611d1d9fc20f0b4345fd827c41ccd5c299a868a05d70edf11", size = 1568901 }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/3b/ab/b3226f0bd7cdcf710fbede2b3548584366da3b19b5021e74f5bde2a8fa3f/pytest-9.0.2-py3-none-any.whl", hash = "sha256:711ffd45bf766d5264d487b917733b453d917afd2b0ad65223959f59089f875b", size = 374801 },
+]
+
 [[package]]
 name = "python-crontab"
 version = "3.2.0"
@@ -869,6 +903,7 @@ dependencies = [
     { name = "pyinstaller" },
     { name = "pymysql" },
     { name = "pyodbc" },
+    { name = "pytest" },
     { name = "python-crontab" },
     { name = "python-dateutil" },
     { name = "requests" },
@@ -905,6 +940,7 @@ requires-dist = [
     { name = "pyinstaller", specifier = ">=6.14.1" },
     { name = "pymysql", specifier = ">=1.1.1" },
     { name = "pyodbc", specifier = ">=5.2.0" },
+    { name = "pytest", specifier = ">=9.0.2" },
     { name = "python-crontab", specifier = ">=3.2.0" },
     { name = "python-dateutil", specifier = ">=2.9.0.post0" },
     { name = "requests", specifier = ">=2.32.3" },