From 7adc895f9b23b6af7ba48e733808110642b95fd2 Mon Sep 17 00:00:00 2001 From: hayat01sh1da Date: Sun, 10 May 2026 05:39:00 +0900 Subject: [PATCH 1/3] Replace Shellscript with pytest execution --- .github/workflows/python.yml | 2 +- python/run_unittests.sh | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 python/run_unittests.sh diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3ff7023..bb250dd 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -77,7 +77,7 @@ jobs: - uses: ./.github/actions/setup-python - name: UnitTest working-directory: ./python - run: bash run_unittests.sh + run: pytest # mypy: # timeout-minutes: 10 # runs-on: ubuntu-latest diff --git a/python/run_unittests.sh b/python/run_unittests.sh deleted file mode 100644 index 74f7a91..0000000 --- a/python/run_unittests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -for directory in $(ls -d */) -do - cd $directory - python -m unittest discover ./test - cd ../ -done From c5c5f6e8149ff82c06acfe5930ee2492899653b8 Mon Sep 17 00:00:00 2001 From: hayat01sh1da Date: Sun, 10 May 2026 05:39:39 +0900 Subject: [PATCH 2/3] Commit pyproject.toml configuration --- python/pyproject.toml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 python/pyproject.toml diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 0000000..b3ad617 --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,11 @@ +[tool.mypy] +python_version = "3.14" +warn_return_any = true +warn_unused_configs = true +disallow_untyped_defs = true + +[tool.pytest.ini_options] +# Configure pytest to properly handle module discovery +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] From c648da067e3092005a8f808298d36861896f2cba Mon Sep 17 00:00:00 2001 From: hayat01sh1da Date: Sun, 10 May 2026 05:40:16 +0900 Subject: [PATCH 3/3] [WIP] Migrate from native unittest to pytest --- python/calculator_cli_app/src/application.py | 5 -- .../test/queries/test_calculation_query.py | 13 ++++- .../test/test_application.py | 24 ++++++-- python/fibonacci_sequence/src/fibonacci.py | 4 +- .../fibonacci_sequence/test/test_fibonacci.py | 9 ++- python/fizzbuzz/src/fizzbuzz.py | 2 + python/fizzbuzz/test/test_fizzbuzz.py | 9 ++- .../test/test_application.py | 6 +- .../test_letter_inspection_application.py | 55 +++++++++++++++++++ python/nabeatsu/src/nabeatsu.py | 2 + python/nabeatsu/test/test_nabeatsu.py | 9 ++- 11 files changed, 121 insertions(+), 17 deletions(-) create mode 100644 python/letter_inspection/test/test_letter_inspection_application.py diff --git a/python/calculator_cli_app/src/application.py b/python/calculator_cli_app/src/application.py index 2cbba1b..b12f9df 100644 --- a/python/calculator_cli_app/src/application.py +++ b/python/calculator_cli_app/src/application.py @@ -1,8 +1,3 @@ -import sys -sys.path.append('./calculator_cli_app/src') -sys.path.append('./calculator_cli_app/src/lib') -sys.path.append('./calculator_cli_app/src/queries') -sys.path.append('./calculator_cli_app/src/validations') from data_type_conversion import __to_int_with_rescue__ from calculation_query import CalculationQuery from args_validation import __validate__ diff --git a/python/calculator_cli_app/test/queries/test_calculation_query.py b/python/calculator_cli_app/test/queries/test_calculation_query.py index 0a3ee16..e3afe94 100644 --- a/python/calculator_cli_app/test/queries/test_calculation_query.py +++ b/python/calculator_cli_app/test/queries/test_calculation_query.py @@ -4,7 +4,18 @@ import glob import os import shutil -sys.path.append('./src/queries') + +# Add src paths relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(os.path.dirname(test_dir)) +src_paths = [ + os.path.join(module_root, 'src', 'queries'), + os.path.join(module_root, 'src') +] +for src_path in src_paths: + if src_path not in sys.path: + sys.path.insert(0, src_path) + from calculation_query import CalculationQuery class TestCalculationQuery(unittest.TestCase): diff --git a/python/calculator_cli_app/test/test_application.py b/python/calculator_cli_app/test/test_application.py index 07a7f8c..0e815b3 100644 --- a/python/calculator_cli_app/test/test_application.py +++ b/python/calculator_cli_app/test/test_application.py @@ -4,10 +4,26 @@ import glob import os import shutil -sys.path.append('./src') -sys.path.append('./src/lib') -sys.path.append('./src/queries') -sys.path.append('./src/validations') + +# Add src paths relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(test_dir) +src_paths = [ + os.path.join(module_root, 'src'), + os.path.join(module_root, 'src', 'lib'), + os.path.join(module_root, 'src', 'queries'), + os.path.join(module_root, 'src', 'validations') +] + +# Remove cached modules to ensure fresh import +for module in list(sys.modules.keys()): + if module in ['application', 'data_type_conversion', 'calculation_query', 'args_validation']: + del sys.modules[module] + +for src_path in src_paths: + if src_path not in sys.path: + sys.path.insert(0, src_path) + from application import Application class TestApplication(unittest.TestCase): diff --git a/python/fibonacci_sequence/src/fibonacci.py b/python/fibonacci_sequence/src/fibonacci.py index b29b6ad..82b43b3 100644 --- a/python/fibonacci_sequence/src/fibonacci.py +++ b/python/fibonacci_sequence/src/fibonacci.py @@ -1,8 +1,10 @@ +__all__ = ['fibonacci'] + def fibonacci(init_num, iter): current_num = init_num next_num = current_num + 1 result = list() - for num in range(init_num, iter + init_num): + for _ in range(init_num, iter + init_num): result.append(current_num) current_num, next_num = next_num, current_num + next_num return result diff --git a/python/fibonacci_sequence/test/test_fibonacci.py b/python/fibonacci_sequence/test/test_fibonacci.py index 811d3a3..4e727d5 100644 --- a/python/fibonacci_sequence/test/test_fibonacci.py +++ b/python/fibonacci_sequence/test/test_fibonacci.py @@ -3,7 +3,14 @@ import glob import os import shutil -sys.path.append('./src') + +# Add src path relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(test_dir) +src_path = os.path.join(module_root, 'src') +if src_path not in sys.path: + sys.path.insert(0, src_path) + from fibonacci import * class TestFibonacci(unittest.TestCase): diff --git a/python/fizzbuzz/src/fizzbuzz.py b/python/fizzbuzz/src/fizzbuzz.py index 30003ff..3d6a44c 100644 --- a/python/fizzbuzz/src/fizzbuzz.py +++ b/python/fizzbuzz/src/fizzbuzz.py @@ -1,3 +1,5 @@ +__all__ = ['fizzbuzz_in_if', 'fizzbuzz_in_ternary'] + def fizzbuzz_in_if(num): if num % 3 == 0 and num % 5 == 0: result = 'FizzBuzz' diff --git a/python/fizzbuzz/test/test_fizzbuzz.py b/python/fizzbuzz/test/test_fizzbuzz.py index aa4d4b0..e19dc6b 100644 --- a/python/fizzbuzz/test/test_fizzbuzz.py +++ b/python/fizzbuzz/test/test_fizzbuzz.py @@ -3,7 +3,14 @@ import glob import os import shutil -sys.path.append('./src') + +# Add src path relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(test_dir) +src_path = os.path.join(module_root, 'src') +if src_path not in sys.path: + sys.path.insert(0, src_path) + from fizzbuzz import * class TestFizzBuzz(unittest.TestCase): diff --git a/python/letter_inspection/test/test_application.py b/python/letter_inspection/test/test_application.py index 9277080..e5fb75c 100644 --- a/python/letter_inspection/test/test_application.py +++ b/python/letter_inspection/test/test_application.py @@ -1,9 +1,7 @@ import unittest -import sys import glob import os import shutil -sys.path.append('./src') from application import Application class TestApplication(unittest.TestCase): @@ -15,7 +13,9 @@ def setUp(self): self.pattern_1 = Application(str_1 = str_1, str_2 = str_2) self.pattern_2 = Application(str_1 = str_1, str_2 = str_3) self.pattern_3 = Application(str_1 = str_1, str_2 = str_4) - self.pycaches = glob.glob(os.path.join('.', '**', '__pycache__'), recursive = True) + test_dir = os.path.dirname(os.path.abspath(__file__)) + module_root = os.path.dirname(test_dir) + self.pycaches = glob.glob(os.path.join(module_root, '**', '__pycache__'), recursive = True) def tearDown(self): for pycache in self.pycaches: diff --git a/python/letter_inspection/test/test_letter_inspection_application.py b/python/letter_inspection/test/test_letter_inspection_application.py new file mode 100644 index 0000000..d5e0440 --- /dev/null +++ b/python/letter_inspection/test/test_letter_inspection_application.py @@ -0,0 +1,55 @@ +import unittest +import sys +import glob +import os +import shutil +import importlib + +# Add src path relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(test_dir) +src_path = os.path.join(module_root, 'src') + +# Remove cached modules to ensure fresh import +for mod in list(sys.modules.keys()): + if mod == 'application': + del sys.modules[mod] + +if src_path not in sys.path: + sys.path.insert(0, src_path) + +from application import Application + +class TestApplication(unittest.TestCase): + def setUp(self): + str_1 = 'hogefoobar' + str_2 = 'abefghooor' + str_3 = 'hoge' + str_4 = 'piyopoopee' + self.pattern_1 = Application(str_1 = str_1, str_2 = str_2) + self.pattern_2 = Application(str_1 = str_1, str_2 = str_3) + self.pattern_3 = Application(str_1 = str_1, str_2 = str_4) + self.pycaches = glob.glob(os.path.join('.', '**', '__pycache__'), recursive = True) + + def tearDown(self): + for pycache in self.pycaches: + if os.path.exists(pycache): + shutil.rmtree(pycache) + +class TestRegularCase(TestApplication): + def test_exactly_equal_size_and_included_1(self): + self.assertTrue(self.pattern_1.exactly_equal_size_and_included()) + +class TestIrregularCase(TestApplication): + pass + +class TestCase1(TestIrregularCase): + def test_exactly_equal_size_and_included_2(self): + self.assertFalse(self.pattern_2.exactly_equal_size_and_included()) + +class TestCase1(TestIrregularCase): + def test_exactly_equal_size_and_included_3(self): + self.assertFalse(self.pattern_3.exactly_equal_size_and_included()) + +if __name__ == '__main__': + unittest.main() diff --git a/python/nabeatsu/src/nabeatsu.py b/python/nabeatsu/src/nabeatsu.py index ed39e51..672668f 100644 --- a/python/nabeatsu/src/nabeatsu.py +++ b/python/nabeatsu/src/nabeatsu.py @@ -1,3 +1,5 @@ +__all__ = ['go_crazy_in_if', 'go_crazy_in_ternary'] + def go_crazy_in_if(num): if num % 3 == 0 or '3' in str(num): # Express the status of 'crazy' with '!' diff --git a/python/nabeatsu/test/test_nabeatsu.py b/python/nabeatsu/test/test_nabeatsu.py index 54544f0..cd1fdd7 100644 --- a/python/nabeatsu/test/test_nabeatsu.py +++ b/python/nabeatsu/test/test_nabeatsu.py @@ -3,7 +3,14 @@ import glob import os import shutil -sys.path.append('./src') + +# Add src path relative to this test file's location +test_dir = os.path.dirname(os.path.abspath(__file__)) +module_root = os.path.dirname(test_dir) +src_path = os.path.join(module_root, 'src') +if src_path not in sys.path: + sys.path.insert(0, src_path) + from nabeatsu import * class TestNabeatsu(unittest.TestCase):