Пример #1
0
def shared_example_of_game(game_class):
    
    with describe(game_class):
        
        with describe("#score"):
                    
            @it("returns 0 for an all gutter game")
            def _(self):
                game = Game()
                for i in range(20): game.roll(0)
                self.assertEqual(game.score(), 0)
            
            def check(self):
                game = Game()
                for i in range(20): game.roll(0)
                self.assertEqual(game.score(), 0)
            
            set_property(verification_func=check)
            
            it("returns 0 for an all gutter game")
Пример #2
0
def _(actual_game_class, context_stack=[]):
    
    with describe("#score"):
                
        @it("returns 0 for an all gutter game")
        def _(self):
            game = actual_game_class()
            for i in range(20): game.roll(0)
            self.assertEqual(game.score(), 0)
        
        def check(self):
            game = actual_game_class()
            for i in range(20): game.roll(0)
            self.assertEqual(game.score(), 0)
        
        set_property(verification_func=check)
        
        it("returns 0 for an all gutter game")
Пример #3
0
# -*- 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)
Пример #4
0
#
# 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, it


class TestGame(unittest.TestCase):
    pass


with describe("Game", test_class=TestGame, a=10, b=20):

    assert a == 10
    assert b == 20

    with describe(".score()", a=99):

        assert a == 99
        assert b == 20

        @it("returns 0")
        def _(testcase):
            pass

    assert a == 10
    assert b == 20
Пример #5
0
# -*- 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_context1")
        assert not hasattr(test_class, "a")
        test_class.a = 1

    @before_example
    def _(self):
        print("  before_example1")
        assert hasattr(self, "a")

        assert not hasattr(self, "b")
        self.b = 1
Пример #6
0
# -*- 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 {0}", 1) as (_, game_id):
    
    assert game_id == 1, game_id
    
    with context("when day is {a}", a=2) as (_, day):
        
        assert day == 2, day
        
        @it("returns foo")
        def _(self):
            self.assertTrue(True)

if __name__ == '__main__':
    import unittest
    unittest.main(verbosity=2)
Пример #7
0
# 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


class TestGame(unittest.TestCase): pass


with describe("Game", test_class=TestGame, a=10):
    
    b = 20
    
    with describe(".score()", a=11):
        
        c = 30
        d = 40
        
        @it("returns 0", a, b, c)
        def _(testcase, a, b, c):
            assert a == 11
            assert b == 20
            assert c == 30
            try: 
                assert d == 40  # => Errror
Пример #8
0
from __future__ import unicode_literals, print_function, division


class Game(object):

    def roll(self, pins):
        pass

    def score(self):
        return 0


import unittest
from uspec import describe, context, it, set_property, expect, eq

with describe(Game):
    
    with describe(Game.score):
                
        @it("returns 0 for an all gutter game")
        def _(self):
            game = Game()
            for i in range(20): game.roll(0)
            expect(game.score()).to(eq(0))
        
        def check(self):
            game = Game()
            for i in range(20): game.roll(0)
            expect(game.score()).to(eq(0))
        
        set_property(verification_func=check)
# 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
Пример #10
0
        def _(self):
            game = actual_game_class()
            for i in range(20): game.roll(0)
            self.assertEqual(game.score(), 0)
        
        def check(self):
            game = actual_game_class()
            for i in range(20): game.roll(0)
            self.assertEqual(game.score(), 0)
        
        set_property(verification_func=check)
        
        it("returns 0 for an all gutter game")


with describe(ConcreteGame):
    it.behaves_like(Game)

########################################################

  
@shared_example_of(Game.score)
def _(game_score_method_generator, context_stack=None):
              
    @it("returns 0 for an all gutter game")
    def _(self):
        game_score_method = game_score_method_generator()
        # for i in range(20): game.roll(0)
        self.assertEqual(game_score_method(), 0)
      
    def check(self):