Skip to content

Commit

Permalink
test: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nogayama committed Mar 5, 2020
1 parent 0f0ba63 commit c995b4d
Show file tree
Hide file tree
Showing 15 changed files with 853 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/README.md
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
56 changes: 56 additions & 0 deletions tests/auto_test_class_creation_nesting_spec.py
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)
65 changes: 65 additions & 0 deletions tests/auto_test_class_creation_spec.py
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)
29 changes: 29 additions & 0 deletions tests/for_statement_spec.py
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)
47 changes: 47 additions & 0 deletions tests/hooks_after.py
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)
75 changes: 75 additions & 0 deletions tests/hooks_after_testable.py
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)
46 changes: 46 additions & 0 deletions tests/hooks_before.py
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)
Loading

0 comments on commit c995b4d

Please sign in to comment.