-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
853 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``` | ||
python -m unittest discover -s tests -p "*.py" -v | ||
``` | ||
|
||
この例を全部テストに入れたいな | ||
|
||
http://www.betterspecs.org/jp/ | ||
|
||
https://relishapp.com/rspec/rspec-core/v/3-9/docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
from uspec import describe, context, it | ||
|
||
TEST_CLASS_NAME_GAME1 = None | ||
TEST_CLASS_NAME_GAME2 = None | ||
TEST_CLASS_NAME_GAME3 = None | ||
TEST_CLASS_NAME_GAME4 = None | ||
|
||
with describe("Game1"): | ||
|
||
TEST_CLASS_NAME_GAME1 = test_class.__name__ | ||
|
||
@it("hoge") | ||
def _(self): | ||
self.assertEqual(self.__class__.__name__, "Test0Game1") | ||
|
||
with describe("Game2"): | ||
|
||
TEST_CLASS_NAME_GAME2 = test_class.__name__ | ||
|
||
@it("hoge") | ||
def _(self): | ||
pass | ||
|
||
with context("Game3"): | ||
|
||
TEST_CLASS_NAME_GAME3 = test_class.__name__ | ||
|
||
@it("hoge") | ||
def _(self): | ||
pass | ||
|
||
with describe("Game4"): | ||
|
||
TEST_CLASS_NAME_GAME4 = test_class.__name__ | ||
|
||
assert TEST_CLASS_NAME_GAME1 in globals() | ||
assert TEST_CLASS_NAME_GAME2 in globals() | ||
assert TEST_CLASS_NAME_GAME3 in globals() | ||
assert TEST_CLASS_NAME_GAME4 not in globals() | ||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
import unittest | ||
import uspec | ||
from uspec import describe, context, it | ||
|
||
|
||
################################### | ||
class TestGame(unittest.TestCase): pass | ||
|
||
|
||
with describe("Game", test_class=TestGame): | ||
|
||
assert test_class is TestGame | ||
|
||
@it("hoge") | ||
def _(self): | ||
self.assertTrue(True) | ||
|
||
assert TestGame is not None | ||
|
||
################################## | ||
TEST_CLASS_NAME_GAME2 = None | ||
|
||
with describe("Game2"): | ||
TEST_CLASS_NAME_GAME2 = test_class.__name__ | ||
|
||
@it("hoge") | ||
def _(self): | ||
self.assertTrue(True) | ||
|
||
assert TEST_CLASS_NAME_GAME2 in globals() | ||
|
||
|
||
################################## | ||
def wrap(): | ||
global TEST_CLASS_NAME_GAME3 | ||
|
||
with describe("Game3"): | ||
|
||
TEST_CLASS_NAME_GAME3 = locals()["test_class"].__name__ | ||
|
||
@it("hoge") | ||
def _(self): | ||
self.assertTrue(True) | ||
|
||
|
||
wrap() | ||
|
||
assert TEST_CLASS_NAME_GAME3 in globals() | ||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
import unittest | ||
from uspec import describe, context, it | ||
|
||
with describe("Game"): | ||
|
||
for idx in range(10): | ||
|
||
with context(idx=idx): | ||
|
||
@it("returns 0", idx) | ||
def _(testcase, idx): | ||
print(idx) | ||
testcase.assertTrue(True) | ||
|
||
if __name__ == '__main__': | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
from uspec import describe, context, it | ||
|
||
with describe("Game"): | ||
|
||
@after_context | ||
def _(test_class): | ||
print("after_context") | ||
assert test_class.a == 0, test_class.a | ||
|
||
@after_example | ||
def _(self): | ||
print("after_example") | ||
assert self.a == 10 | ||
assert self.b == 1 | ||
self.b = 0 | ||
self.__class__.a = 0 | ||
|
||
@it("mehod1") | ||
def _(self): | ||
print(" method1") | ||
self.b = 1 | ||
self.__class__.a = 10 | ||
|
||
def verify(self): | ||
print(" method2") | ||
self.b = 1 | ||
self.__class__.a = 10 | ||
|
||
set_property(verification_func=verify) | ||
it("method2") | ||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
from uspec import describe, context, it | ||
|
||
with describe("Game"): | ||
|
||
@after_example | ||
def _(self): | ||
# second | ||
print(" after_example1") | ||
assert self.__class__.a == 10 | ||
assert self.b == 1 | ||
assert self.__class__.A == 10 | ||
assert self.B == 0 | ||
self.__class__.a = 0 | ||
|
||
@after_context | ||
def _(test_class): | ||
# fourth | ||
print("after_context1") | ||
assert test_class.a == 0 | ||
assert test_class.A == 0 | ||
|
||
with context("#score"): | ||
|
||
@after_example | ||
def _(self): | ||
# first | ||
print(" after_example2") | ||
assert self.__class__.a == 10 | ||
assert self.b == 1 | ||
assert self.__class__.A == 10 | ||
assert self.B == 1 | ||
self.B = 0 | ||
|
||
@after_context | ||
def _(test_class): | ||
# third | ||
print("after_context2") | ||
assert test_class.A == 10 | ||
assert test_class.a == 0 | ||
test_class.A = 0 | ||
|
||
@it("mehod1") | ||
def _(self): | ||
print(" method1") | ||
self.b = 1 | ||
self.B = 1 | ||
self.__class__.a = 10 | ||
self.__class__.A = 10 | ||
|
||
def verify(self): | ||
print(" method2") | ||
self.b = 1 | ||
self.B = 1 | ||
self.__class__.a = 10 | ||
self.__class__.A = 10 | ||
|
||
set_property(verification_func=verify) | ||
it("method2") | ||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main(verbosity=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# ================================================================= | ||
# uspec | ||
# | ||
# Copyright (c) 2020 Takahide Nogayama | ||
# | ||
# This software is released under the MIT License. | ||
# http://opensource.org/licenses/mit-license.php | ||
# ================================================================= | ||
|
||
from __future__ import unicode_literals, print_function, division | ||
|
||
from uspec import describe, context, it | ||
|
||
with describe("Game"): | ||
|
||
@before_context | ||
def _(test_class): | ||
print("before_context") | ||
assert not hasattr(test_class, "a") | ||
test_class.a = 1 | ||
|
||
@before_example | ||
def _(self): | ||
print("before_example") | ||
assert hasattr(self, "a") | ||
|
||
assert not hasattr(self, "b") | ||
self.b = 1 | ||
|
||
@it("mehod1") | ||
def _(self): | ||
print(" method1") | ||
assert self.b == 1 | ||
|
||
def verify(self): | ||
print(" method2") | ||
assert self.b == 1 | ||
|
||
set_property(verification_func=verify) | ||
it("method2") | ||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main(verbosity=2) |
Oops, something went wrong.