From a68fbdb5f877577caf5563e058e3121d5adab377 Mon Sep 17 00:00:00 2001 From: Takayuki Kamiyama Date: Tue, 31 Oct 2023 13:35:18 +0900 Subject: [PATCH 1/4] Delete. --- unit/test_run.py | 51 ------------------------------------------------ 1 file changed, 51 deletions(-) delete mode 100644 unit/test_run.py diff --git a/unit/test_run.py b/unit/test_run.py deleted file mode 100644 index 03f3d0b..0000000 --- a/unit/test_run.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys -import unittest -from typing import Optional - - -# Python Version Check. -class Checker: - def version(self): - major: Optional[int] = sys.version_info[0] - minor: Optional[int] = sys.version_info[1] - print("Python " + str(major) + "." + str(minor) + " :", id(self)) - - -# Unit Test. -class VersionTest(unittest.TestCase): - @classmethod - def setupClass(cls): - print("setupClass") - - @classmethod - def tearDownClass(cls): - print("tearDownClass") - - # Create Instance. - def setUp(self): - self.checker = Checker() - print("setUp", id(self)) - - def tearDown(self): - self.checker.version() - print("tearDown", id(self)) - - # Python Version: 3.x == 3.x - def test_check_major(self): - py_major: Optional[int] = sys.version_info[0] - major_calc = int(py_major) - set_major = int(3) - print("test_check_major", id(self)) - self.assertEqual(major_calc, set_major) - - # Python Version: (x.11 or x.10) > x.4 - def test_check_minor(self): - py_minor: Optional[int] = sys.version_info[1] - minor_calc = int(py_minor) - set_minor = int(4) - print("test_check_minor", id(self)) - self.assertGreater(minor_calc, set_minor) - - -if __name__ == '__main__': - unittest.main() From f371ad67012d010a51f6cc9e0056457591ec44e5 Mon Sep 17 00:00:00 2001 From: Takayuki Kamiyama Date: Tue, 31 Oct 2023 13:35:26 +0900 Subject: [PATCH 2/4] Create. --- unit/unit.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 unit/unit.py diff --git a/unit/unit.py b/unit/unit.py new file mode 100644 index 0000000..03f3d0b --- /dev/null +++ b/unit/unit.py @@ -0,0 +1,51 @@ +import sys +import unittest +from typing import Optional + + +# Python Version Check. +class Checker: + def version(self): + major: Optional[int] = sys.version_info[0] + minor: Optional[int] = sys.version_info[1] + print("Python " + str(major) + "." + str(minor) + " :", id(self)) + + +# Unit Test. +class VersionTest(unittest.TestCase): + @classmethod + def setupClass(cls): + print("setupClass") + + @classmethod + def tearDownClass(cls): + print("tearDownClass") + + # Create Instance. + def setUp(self): + self.checker = Checker() + print("setUp", id(self)) + + def tearDown(self): + self.checker.version() + print("tearDown", id(self)) + + # Python Version: 3.x == 3.x + def test_check_major(self): + py_major: Optional[int] = sys.version_info[0] + major_calc = int(py_major) + set_major = int(3) + print("test_check_major", id(self)) + self.assertEqual(major_calc, set_major) + + # Python Version: (x.11 or x.10) > x.4 + def test_check_minor(self): + py_minor: Optional[int] = sys.version_info[1] + minor_calc = int(py_minor) + set_minor = int(4) + print("test_check_minor", id(self)) + self.assertGreater(minor_calc, set_minor) + + +if __name__ == '__main__': + unittest.main() From fc114dd9fadc0fa4a9bbec80fd114d821e5831d9 Mon Sep 17 00:00:00 2001 From: Takayuki Kamiyama Date: Tue, 31 Oct 2023 13:35:32 +0900 Subject: [PATCH 3/4] Create. --- unit/xunit.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 unit/xunit.py diff --git a/unit/xunit.py b/unit/xunit.py new file mode 100644 index 0000000..fb1efae --- /dev/null +++ b/unit/xunit.py @@ -0,0 +1,103 @@ +class TestResult: + def __init__(self): + self.runCount = 0 + self.errorCount = 0 + + def testStarted(self): + self.runCount = self.runCount + 1 + + def testFailed(self): + self.errorCount = self.errorCount + 1 + + def summary(self): + return "%d run, %d failed" % (self.runCount, self.errorCount) + + +class TestCase: + def __init__(self, name): + self.name = name + + def setUp(self): + pass + + def tearDown(self): + pass + + def run(self, result): + result.testStarted() + self.setUp() + try: + method = getattr(self, self.name) + method() + except Exception: + result.testFailed() + self.tearDown() + + +class TestSuite: + def __init__(self): + self.tests = [] + + def add(self, test): + self.tests.append(test) + + def run(self, result): + for test in self.tests: + test.run(result) + + +class WasRun(TestCase): + def setUp(self): + self.log = "setUp " + + def testMethod(self): + self.log = self.log + "testMethod " + + def testBrokenMethod(self): + raise Exception + + def tearDown(self): + self.log = self.log + "tearDown " + + +class TestCaseTest(TestCase): + def setUp(self): + self.result = TestResult() + + def testTempleteMethod(self): + test = WasRun("testMethod") + test.run(self.result) + assert ("setUp testMethod tearDown " == test.log) + + def testResult(self): + test = WasRun("testMethod") + test.run(self.result) + assert ("1 run, 0 failed" == self.result.summary()) + + def testFailedResult(self): + test = WasRun("testBrokenMethod") + test.run(self.result) + assert ("1 run, 1 failed" == self.result.summary()) + + def testFailedResultFormatting(self): + self.result.testStarted() + self.result.testFailed() + assert ("1 run, 1 failed" == self.result.summary()) + + def testSuite(self): + suite = TestSuite() + suite.add(WasRun("testMethod")) + suite.add(WasRun("testBrokenMethod")) + suite.run(self.result) + assert ("2 run, 1 failed" == self.result.summary()) + + +suite = TestSuite() +suite.add(TestCaseTest("testTempleteMethod")) +suite.add(TestCaseTest("testResult")) +suite.add(TestCaseTest("testFailedResult")) +suite.add(TestCaseTest("testFailedResultFormatting")) +suite.add(TestCaseTest("testSuite")) +result = TestResult() +suite.run(result) +print(result.summary()) From 6d5e1e3d5456075322c76216a9fe3ac514199242 Mon Sep 17 00:00:00 2001 From: Takayuki Kamiyama Date: Tue, 31 Oct 2023 13:35:38 +0900 Subject: [PATCH 4/4] Update. --- pake.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pake.py b/pake.py index 8d1431e..25821c8 100644 --- a/pake.py +++ b/pake.py @@ -1,3 +1,15 @@ -with open('./unit/test_run.py') as ut: +# Run, unit/xunit.py + +print('----------------------------------------------------------------------') + +with open('./unit/xunit.py') as xut: + xcmd = xut.read() + exec(xcmd) + +print('----------------------------------------------------------------------') + +# Run, unit/unit.py + +with open('./unit/unit.py') as ut: cmd = ut.read() exec(cmd)