# Copyright © 2019 National Institute of Advanced Industrial Science and Technology (AIST). All rights reserved.
from datetime import datetime
from nose2.tools import such

from . import app
from qai_testbed_backend.usecases.test_description import TestDescriptionService
from qai_testbed_backend.controllers.dto.test_description import AppendTestDescriptionReqSchema, \
    PutTestDescriptionsReqSchema
from qai_testbed_backend.across.exception import QAIException, QAINotFoundException, QAIInvalidRequestException

with such.A('/<organizer_id>/ml_components/<ml_component_id>/testDescriotions'
            ) as it:

    # テスト実行時に1回実行
    @it.has_setup
    def setup():
        pass

    @it.has_teardown
    def teardown():
        pass

    # テスト関数読むたびに実行
    @it.has_test_setup
    def setup_each_test_case():
        pass

    @it.has_test_teardown
    def teardown_setup_each_test_case():
        pass
示例#2
0
    mocked_response = {
        "Parameter": {
            "Value": yaml.safe_dump({"regions": expected_result})
        }
    }
    mocked_betterboto_client().__enter__(
    ).get_parameter.return_value = mocked_response

    # execute
    actual_result = sut.get_regions()

    # verify
    assert actual_result == expected_result


with such.A("get_config") as it:

    @it.should("work")
    @params(
        ({
            "hello": "world"
        }, {
            "foo": "bar"
        }, {
            "hello": "world",
            "foo": "bar"
        }),
        ({}, {
            "foo": "bar"
        }, {
            "foo": "bar"
示例#3
0
import os
from nose2.tools import such
from sideeye import config, parser, Point, Fixation, Trial, Item

with such.A(".ASC Parser") as it:

    @it.has_setup
    def setup():
        it.asc_header = """
        MSG 1 SYNCTIME
        MSG 1000 TRIALID E1I1D0
        MSG 1001 REGION CHAR 1 1 T 10 100 20 110
        MSG 1002 REGION CHAR 1 1 e 20 100 30 110
        MSG 1003 REGION CHAR 1 1 s 30 100 40 110
        MSG 1004 REGION CHAR 1 1 t 40 100 50 110
        MSG 1005 REGION CHAR 1 1   50 100 60 110
        MSG 1006 REGION CHAR 1 1 i 60 100 70 110
        MSG 1007 REGION CHAR 1 1 t 70 100 80 110
        MSG 1008 REGION CHAR 1 1 e 80 100 90 110
        MSG 1009 REGION CHAR 1 1 m 90 100 100 110
        """
        it.asc_end = """
        MSG 10001 TRIAL_RESULT 7
        MSG 10002 TRIAL OK
        """
        it.items = {
            "1": {
                "1": Item("1", "1", parser.region.text("Test/ item"))
            }
        }
from nose2.tools import such
from misc.distributions import Categorical, Gaussian, Product, Bernoulli
import numpy as np
import tensorflow as tf

sess = tf.Session()


def random_softmax(ndim):
    x = np.random.uniform(size=(ndim, ))
    x = x - np.max(x)
    x = np.exp(x) / np.sum(np.exp(x))
    return np.cast['float32'](x)


with such.A("Product Distribution") as it:
    dist1 = Product([Categorical(5), Categorical(3)])
    dist2 = Product([Gaussian(5), dist1])

    @it.should
    def test_dist_info_keys():
        it.assertEqual(set(dist1.dist_info_keys), {"id_0_prob", "id_1_prob"})
        it.assertEqual(
            set(dist2.dist_info_keys),
            {"id_0_mean", "id_0_stddev", "id_1_id_0_prob", "id_1_id_1_prob"})

    @it.should
    def test_kl_sym():
        old_id_0_prob = np.array([random_softmax(5)])
        old_id_1_prob = np.array([random_softmax(3)])
        new_id_0_prob = np.array([random_softmax(5)])
示例#5
0
import mock

import requests
import hdlcc.utils as utils

_logger = logging.getLogger(__name__)

HDLCC_SERVER_LOG_LEVEL = os.environ.get('HDLCC_SERVER_LOG_LEVEL', 'INFO')
HDLCC_BASE_PATH = p.abspath(p.join(p.dirname(__file__), '..', '..'))

def doNothing(queue):
    _logger.debug("I'm ready")
    queue.get()
    _logger.debug("Ok, done")

with such.A("hdlcc server") as it:
    def startCodeCheckerServer():
        hdlcc_server_fname = p.join(HDLCC_BASE_PATH, 'hdlcc',
                                    'hdlcc_server.py')

        it._host = '127.0.0.1'
        it._port = '50000'
        it._url = 'http://{0}:{1}'.format(it._host, it._port)
        cmd = ['coverage', 'run',
               hdlcc_server_fname,
               '--host', it._host, '--port', it._port,
               '--log-level', HDLCC_SERVER_LOG_LEVEL,
               '--stdout', 'hdlcc-stdout.log',
               '--stderr', 'hdlcc-stderr.log',
               '--log-stream', 'hdlcc.log',]

class Layer2(object):

    description = "Layer2"

    @classmethod
    def setUp(cls):
        log.info("Called setup in layer 2")

    @classmethod
    def tearDown(cls):
        log.info("Called teardown in layer 2")


with such.A("system with setup") as it:

    it.uses(Layer1)

    @it.should("do something")
    def test(case):
        it.assertTrue(it.unique_resource.used)

    with it.having("another setup"):

        it.uses(Layer2)

        @it.should("do something else")  # noqa: F811
        def test(case):  # noqa: F811
            it.assertTrue(it.unique_resource.used)
示例#7
0
import numpy as np
import MeCab
from scipy.sparse import csr_matrix
from nose2.tools import such
from shortscikit.feature_extracttion.text import JapaneseTokenizer
from sklearn.feature_extraction.text import CountVectorizer
from janome.tokenizer import Tokenizer as JanomeTokenizer

with such.A('sample test') as it:

    with it.having('MeCab wakati only JapaneseTokenizer test group'):
        mecab_wakati_tokenizer = JapaneseTokenizer('MeCab')
        mecab_wakati_test_str = 'すもももももももものうち'
        mecab_wakati_test_tokenizer = MeCab.Tagger('-Owakati')
        mecab_wakati_test_result = mecab_wakati_test_tokenizer.parse(
            mecab_wakati_test_str).split(' ')[:-1]
        mecab_wakati_count_vectorizer = CountVectorizer(
            tokenizer=mecab_wakati_tokenizer.fit_transform)
        mecab_wakati_vectorizer_test = ['すもももすももももももすもももももももももすももももものうち']
        mecab_wakati_result0 = mecab_wakati_count_vectorizer.fit_transform(
            mecab_wakati_vectorizer_test).sorted_indices()
        mecab_wakati_result1 = csr_matrix(
            ([1, 4, 1, 7, 4], ([0, 0, 0, 0, 0], [0, 1, 2, 3, 4])),
            shape=(1, 5))

        @it.should('JapaneseTokenizer fit method')
        def mecab_wakati_test1(case):
            it.assertIsInstance(
                mecab_wakati_tokenizer.fit(mecab_wakati_test_str),
                JapaneseTokenizer)
示例#8
0

class Layer2(object):

    description = 'Layer2'

    @classmethod
    def setUp(cls):
        log.info("Called setup in layer 2")

    @classmethod
    def tearDown(cls):
        log.info("Called teardown in layer 2")


with such.A('system with setup') as it:

    it.uses(Layer1)

    @it.should('do something')
    def test(case):
        it.assertTrue(it.unique_resource.used)

    with it.having('another setup'):

        it.uses(Layer2)

        @it.should('do something else')
        def test(case):
            it.assertTrue(it.unique_resource.used)
示例#9
0
from nose2.tools import such

with such.A('system') as it:

    @it.should('do something')
    def test():
        pass


it.createTests(globals())
示例#10
0
from nose2.tools import such
from sideeye import Point, Fixation, Saccade, Region, Item, Trial

with such.A("Trial") as it:

    @it.has_setup
    def setup():
        it.r1 = Region(Point(1, 1), Point(2, 2), 1, "region 1")
        it.r2 = Region(Point(1, 1), Point(2, 2), 1, "region 2")
        it.r3 = Region(Point(1, 1), Point(2, 2), 1, "region 3")
        it.fix1 = Fixation(Point(1, 2), 3, 4, 0, "region")
        it.fix2 = Fixation(Point(1, 2), 5, 6, 1, "region")
        it.fixations = [
            Fixation(Point(1, 2), 10, 20, 0, "region"),
            Fixation(Point(2, 2), 30, 40, 1, "region"),
            Fixation(Point(3, 2), 50, 60, 2, "region"),
            Fixation(Point(4, 2), 70, 80, 3, "region", excluded=True),
            Fixation(Point(1, 2), 90, 100, 4, "region"),
            Fixation(Point(2, 2), 110, 120, 5, "region", excluded=True),
            Fixation(Point(3, 2), 130, 140, 6, "region", excluded=True),
            Fixation(Point(4, 2), 150, 160, 7, "region"),
            Fixation(Point(5, 2), 170, 180, 8, "region", excluded=True),
        ]
        it.item = Item(2, 1, [it.r1, it.r2, it.r3])
        it.trial = Trial(1, 5, it.item, it.fixations)
        it.trial_include_fixations = Trial(1,
                                           5,
                                           it.item,
                                           it.fixations,
                                           include_fixation=True)
        it.trial_include_saccades = Trial(1,
示例#11
0
def ll_cycle():
    el1 = Node(2)
    el2 = Node(4)
    el3 = Node(8)
    el4 = Node(11)

    el1.next = el2
    el2.next = el3
    el3.next = el4
    el4.next = el2

    return LinkedList(el1)


with such.A("Linked list") as it:

    @it.should("reverse list")
    def test_reverse():
        ll = ll_1()
        ll.reverse()
        expected = [8, 5, 4, 3]
        it.assertEqual(list(ll), expected)

    @it.should("merge two sorted lists")
    def test_merge():
        ll1 = ll_1()
        ll2 = ll_2()
        result = list(ll1.merge(ll2))

        expected = [2, 3, 4, 4, 5, 8, 8, 11]
示例#12
0
    @classmethod
    def setUp(cls):
        print("YEAH")
        it.obj = False


class Layer2(object):

    description = "Layer2 description"

    @classmethod
    def setUp(cls):
        it.obj = slow_blocking_init()


with such.A('system with a fast initial setup layer') as it:

    it.uses(Layer1)

    @it.should('not have obj initialized')
    def test():
        assert not it.obj


    with it.having('a second slow setup layer'):

        it.uses(Layer2)

        @it.should('have obj initialized')
        def test():
            assert it.obj
示例#13
0
# Copyright © 2019 National Institute of Advanced Industrial Science and Technology (AIST). All rights reserved.
import time
from nose2.tools import such

from . import app
from qai_testbed_backend.usecases.testrunner import ReportGeneratorService, TestRunnerService, TestRunnerStatusService
from qai_testbed_backend.usecases.test_description import TestDescriptionService
from qai_testbed_backend.usecases.ml_framework import MLFrameworkService
from qai_testbed_backend.controllers.dto.testrunner import PostReportGeneratorReq, PostTestRunnerReq, GraphsTemplate, GraphParam
from qai_testbed_backend.controllers.dto.test_description import GetTestDescriptionDetailRes
from qai_testbed_backend.across.exception import QAIException
from qai_testbed_backend.gateways.extensions import sql_db


with such.A('/<organizer_id>/ml_components/<ml_component_id>/testDescriotions/reportGenerator') as it:

    # テスト実行時に1回実行
    @it.has_setup
    def setup():
        # TD1 run 作成
        with app.app_context():
            from qai_testbed_backend.entities.test_description import TestDescriptionMapper
            from qai_testbed_backend.entities.run import RunMapper
            from qai_testbed_backend.entities.job import JobMapper
            from qai_testbed_backend.entities.test import TestMapper
            from qai_testbed_backend.entities.ml_component import MLComponentMapper
            from qai_testbed_backend.entities.graph import GraphMapper
            from qai_testbed_backend.entities.graph_template import GraphTemplateMapper
            from qai_testbed_backend.entities.test_runner import TestRunnerMapper

            test_runner = TestRunnerMapper.query.\
示例#14
0
#!/usr/bin/env python
"""
Use nose2 to test the classes and functions found in the tttio package
"""

import logging
import os
import datetime
from nose2.tools import such
import tttio
from tttio import ai, boards, tttoe

logging.getLogger().setLevel(logging.INFO)
logging.getLogger().removeHandler(tttio.consoleHandler)

with such.A(
        'system running on linux, windows or osx, python version 2.7') as it:

    with it.having('all data files are in the correct location'):

        @it.has_setup
        def setup():
            # forms the path HERE/../data b/c the package is setup like this: TicTacTio -> (tests, data, etc.)
            it.data_dir = os.path.join(
                os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'),
                'data')
            it.data_files = ['ai_default.txt', 'background.jpg']

        @it.has_teardown
        def teardown():
            del it.data_dir
            del it.data_files
示例#15
0
# Copyright © 2019 National Institute of Advanced Industrial Science and Technology (AIST). All rights reserved.
from datetime import datetime
from nose2.tools import such

from . import app, get_random_str
from qai_testbed_backend.usecases.inventory import InventoryService
from qai_testbed_backend.controllers.dto.inventory import PutInventoryReq, AppendInventoryReq
from qai_testbed_backend.across.exception import QAIException, QAINotFoundException, QAIInvalidRequestException


with such.A('inventories') as it:

    with it.having('GET /inventories'):
        @it.should('should return I12000.')
        def test():
            with app.app_context():
                response = InventoryService().get_inventories(organizer_id='dep-a', ml_component_id=1)
                it.assertEqual(response.result.code, 'I12000')

        @it.should('should return I14000 if `organizer_id` is not found.')
        def test():
            with app.app_context():
                try:
                    InventoryService().get_inventories(organizer_id='hoge',  # invalid
                                                       ml_component_id=1)
                    it.fail()
                except QAIException as e:
                    it.assertTrue(type(e) is QAINotFoundException)
                    it.assertEqual(e.result_code, 'I14000')

        @it.should('should return I14000 if `ml_component_id` is not found.')
示例#16
0
import os
from nose2.tools import such
from sideeye import calculate_all_measures, parser

with such.A("Output Generator") as it:

    @it.has_setup
    def setup():
        dirname = os.path.dirname(os.path.realpath(__file__))
        it.experiment = parser.experiment.parse(
            os.path.join(dirname, "testdata/timdrop.DA1"),
            os.path.join(dirname, "testdata/timdropDA1.cnt"),
        )

    @it.should("generate output in long format.")
    def test_long_output():
        output = calculate_all_measures([it.experiment])
        it.assertEqual(
            output.split("\n")[0],
            """experiment_name,trial_id,trial_total_time,item_id,item_condition,\
region_number,location_first_regression,latency_first_regression,fixation_count,\
percent_regressions,average_forward_saccade,average_backward_saccade,skip,\
first_pass_regressions_out,first_pass_regressions_in,first_fixation_duration,\
single_fixation_duration,first_pass,go_past,total_time,right_bounded_time,\
reread_time,second_pass,spillover_time,refixation_time,landing_position,\
launch_site,first_pass_fixation_count,go_back_time_region,go_back_time_char""",
        )


it.createTests(globals())
示例#17
0
TEST_TEMP_PATH = getTestTempPath(__name__)
TEST_PROJECT = p.abspath(p.join(TEST_TEMP_PATH, "test_project"))

SERVER_LOG_LEVEL = os.environ.get("SERVER_LOG_LEVEL", "INFO")

_logger = logging.getLogger(__name__)
HDL_CHECKER_BASE_PATH = p.abspath(p.join(p.dirname(__file__), "..", ".."))


def _path(*args):
    # type: (str) -> str
    "Helper to reduce foorprint of p.join(TEST_TEMP_PATH, *args)"
    return p.join(TEST_TEMP_PATH, *args)


with such.A("hdl_checker bottle app") as it:
    # Workaround for Python 2.x and 3.x differences
    if six.PY2:
        it.assertCountEqual = assertCountEqual(it)

    @it.has_setup
    def setup():
        setupTestSuport(TEST_TEMP_PATH)

        it.project_file = p.join(TEST_PROJECT, "vimhdl.prj")
        it.app = TestApp(handlers.app)

    @it.should("get diagnose info without any project")
    @disableVunit
    def test():
        reply = it.app.post_json("/get_diagnose_info")
示例#18
0
    for path in (p.join(base_path, 'python'),
                 p.join(base_path, 'dependencies', 'requests')):
        print(path)
        sys.path.insert(0, path)

_setupPaths()

# pylint: disable=import-error,wrong-import-position
from vimhdl_tests.vim_mock import mockVim
mockVim()
import vim
import vimhdl  # pylint: disable=unused-import
import vimhdl.vim_helpers as vim_helpers
# pylint: enable=import-error,wrong-import-position

with such.A('vim_helpers module') as it:
    @it.should("return all buffer variables from the current buffer if "
               "neither buffer or variable are defined")
    def test():
        it.assertEquals(
            vim_helpers._getBufferVars(),
            {'current_buffer_var_0' : 'current_buffer_value_0',
             'current_buffer_var_1' : 'current_buffer_value_1'})

    @it.should("return the given buffer variable of the current buffer if "
               "only the first one is given")
    def test():
        it.assertEquals(vim_helpers._getBufferVars(var='current_buffer_var_0'),
                        'current_buffer_value_0')
        it.assertEquals(vim_helpers._getBufferVars(var='current_buffer_var_1'),
                        'current_buffer_value_1')
示例#19
0
""" Tests for ex_002_even_fib"""
from itertools import takewhile
from nose2.tools import such
import nose2
from src import ex_002_even_fib as mut # mut = Module Under Test

with such.A('Exercise 002 - Fibonacci generator') as it:
    @it.should('Generate Fib numbers up to 90')
    def test_generator():
        """ Test the fibonacci generator"""
        less_than_90 = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
        generated = [fib_no for fib_no in takewhile(
            lambda x: x < 90, mut.fibonacci_generator())]
        assert less_than_90 == generated, \
            "Equals failed generated vs Hard coded {0}".format(generated)
    @it.should('Sum up all the even fib-numbers up to 90')
    def test_sum_of_even():
        """ Tests the sum_of_even_fibonacci_numbers method """
        # Even fib numbers below 90 are 2 8 34
        evensum = 2 + 8 + 34
        mutsum = mut.sum_of_even_fibonacci_numbers(90)
        assert evensum == mutsum, "Incorrect sum, expected {0} got {1}".format(evensum, mutsum)
    @it.should('Solve the actual Euler problem correctly')
    def test_main():
        """ Tests the main method, compares to the correct Euler answer 4613732"""
        answer = 4613732
        mut_answer = mut.run_main()
        assert answer == mut_answer, \
            "Main calculation incorrect,got {} expected {}".format(mut_answer, answer)

it.createTests(globals())
示例#20
0
from nose2.tools import such

with such.A("test scenario with errors") as it:

    @it.has_setup
    def setup_fail():
        raise RuntimeError("Bad Error in such setUp!")

    @it.should("check that value == 1")
    def test_passes(case):
        pass


it.createTests(globals())
示例#21
0
from nose2.tools import such

from garage.misc import instrument


class TestClass(object):
    @property
    def arr(self):
        return [1, 2, 3]

    @property
    def compound_arr(self):
        return [dict(a=1)]


with such.A("instrument") as it:

    @it.should
    def test_concretize():
        it.assertEqual(instrument.concretize([5]), [5])
        it.assertEqual(instrument.concretize((5, )), (5, ))
        fake_globals = dict(TestClass=TestClass)
        instrument.stub(fake_globals)
        modified = fake_globals["TestClass"]
        it.assertIsInstance(modified, instrument.StubClass)
        it.assertIsInstance(modified(), instrument.StubObject)
        it.assertEqual(instrument.concretize((5, )), (5, ))
        it.assertIsInstance(instrument.concretize(modified()), TestClass)

    @it.should
    def test_chained_call():
from nose2.tools import such
from unittest import mock

import frontend

with such.A('Calculator Web Frontend') as it:
    with it.having('Home Page'):

        @it.should('display the home page')
        @mock.patch('frontend.request')
        def test(request_mock):
            request_mock.method = 'GET'
            html = frontend.home()
            it.assertIn('Home Page', html)

        with it.having('addition form'):

            @it.should('display the form')
            @mock.patch('frontend.request')
            def test(request_mock):
                request_mock.method = 'GET'
                html = frontend.home()
                it.assertIn('<form', html)
                it.assertIn('name="first"', html)
                it.assertIn('name="second"', html)

            @it.should('delegate request parameters to backend.add')
            @mock.patch('frontend.request')
            @mock.patch('frontend.backend')
            def test(backend_mock, request_mock):
                request_mock.method = 'POST'
示例#23
0
    given_a_series_of_prices(goog, prices)
    assert goog.is_increasing_trend() == expected_output


def test_trend_with_all_consecutive_values_upto_100():
    for i in range(100):
        yield stock_trends_with_consecutive_prices, [i, i+1, i+2]


def stock_trends_with_consecutive_prices(prices):
    goog = Stock("GOOG")
    given_a_series_of_prices(goog, prices)
    assert goog.is_increasing_trend()


with such.A("Stock class") as it:

    @it.has_setup
    def setup():
        it.goog = Stock("GOOG")

    with it.having("a price method"):
        @it.has_setup
        def setup():
            it.goog.update(datetime(2014, 2, 12), price=10)

        @it.should("return the price")
        def test(case):
            assert it.goog.price == 10

        @it.should("return the latest price")
示例#24
0
# Copyright © 2019 National Institute of Advanced Industrial Science and Technology (AIST). All rights reserved.
from nose2.tools import such

from . import app
from qai_testbed_backend.usecases.testrunner import TestRunnerService


with such.A('TestRunners') as it:

    with it.having('GET /testRunners'):
        @it.should('should return I52000.')
        def test():
            with app.app_context():
                response = TestRunnerService().get_test_runners()
                it.assertEqual(response.result.code, 'I52000')

        @it.should('should return TestRunners.')
        def test():
            with app.app_context():
                response = TestRunnerService().get_test_runners()

                for t in response.test_runners:
                    it.assertTrue(type(t.id_) is int)
                    it.assertNotEqual(t.id_, 0)
                    it.assertTrue(type(t.name) is str)
                    it.assertNotEqual(t.name, '')
                    it.assertTrue(type(t.quality_dimension_id) is int)
                    it.assertNotEqual(t.quality_dimension_id, 0)
                    it.assertTrue(type(t.description) is str)
                    it.assertTrue(type(t.author) is str)
                    it.assertTrue(type(t.version) is str)
示例#25
0
import logging
log = logging.getLogger(__name__)

from nose2.tools import such

with such.A('foo') as it:
    it.upper_run = 0
    it.lower_run = 0
    
    @it.has_test_setup
    def upper_test_setup(case):
        log.error('foo::setUp')
        it.upper_run += 1
 
    @it.should("run upper setups")
    def test_run_upper_setups(case):
        case.assertEquals(it.upper_run, 1)
        case.assertEquals(it.lower_run, 0)
        
    with it.having('some bar'):
        @it.has_test_setup
        def lower_test_setup(case):
            log.error('foo some bar::setUp')
            it.lower_run += 1
 
        @it.should("run all setups")
        def test_run_all_setups(case):
            case.assertEquals(it.upper_run, 2)
            case.assertEquals(it.lower_run, 1)

        @it.should("run all setups again")
示例#26
0
import os
from nose2.tools import such
from sideeye import config, parser, Point, Fixation, Trial, Region, Item

with such.A("Parser") as it:
    with it.having("DA1 parser"):

        @it.has_setup
        def setup_da1():
            it.dirname = os.path.dirname(os.path.realpath(__file__))
            it.timdrop_items = parser.region.file(
                os.path.join(it.dirname, "testdata/timdropDA1.cnt"))
            it.config = config.Configuration()
            it.config.region_fields.number = 1
            it.config.region_fields.condition = 0
            it.config.region_fields.boundaries_start = 3
            it.config.region_fields.includes_y = True
            it.robodoc_items = parser.region.file(
                os.path.join(it.dirname, "testdata/robodocDA1.reg"), it.config)
            it.timdrop_DA1 = parser.da1.parse(
                os.path.join(it.dirname, "testdata/timdrop.DA1"),
                it.timdrop_items,
                it.config,
            )
            it.config.da1_fields.time = 3
            it.robodoc_DA1 = parser.da1.parse(
                os.path.join(it.dirname, "testdata/robodoc.DA1"),
                it.robodoc_items,
                it.config,
            )
示例#27
0
class SomeLayer(object):
    @classmethod
    def setUp(cls):
        it.somelayer = True

    @classmethod
    def tearDown(cls):
        del it.somelayer

#
# Such tests start with a declaration about the system under test
# and will typically bind the test declaration to a variable with
# a name that makes nice sentences, like 'this' or 'it'.
#
with such.A('system with complex setup') as it:

    #
    # Each layer of tests can define setup and teardown methods.
    # setup and teardown methods defined here run around the entire
    # group of tests, not each individual test.
    #
    @it.has_setup
    def setup():
        it.things = [1]

    @it.has_teardown
    def teardown():
        it.things = []

    #
示例#28
0
from nose2.tools import such

with such.A('test scenario with errors') as it:

    @it.has_setup
    def setup_fail():
        raise RuntimeError('Bad Error in such setUp!')

    @it.should('check that value == 1')
    def test_passes(case):
        pass


it.createTests(globals())
import logging

from nose2.tools import such

log = logging.getLogger(__name__)

with such.A("foo") as it:
    it.upper_run = 0
    it.lower_run = 0

    @it.has_test_setup
    def upper_test_setup(case):
        log.error("foo::setUp")
        it.upper_run += 1

    @it.should("run upper setups")
    def test_run_upper_setups(case):
        case.assertEqual(it.upper_run, 1)
        case.assertEqual(it.lower_run, 0)

    with it.having("some bar"):

        @it.has_test_setup
        def lower_test_setup(case):
            log.error("foo some bar::setUp")
            it.lower_run += 1

        @it.should("run all setups")
        def test_run_all_setups(case):
            case.assertEqual(it.upper_run, 2)
            case.assertEqual(it.lower_run, 1)
示例#30
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from nose2.tools import such

with such.A('system') as it:

    with it.having('something'):

        @it.should("do stuff")
        def test_should_do_stuff(case):
            pass

    it.createTests(globals())

with such.A('another system') as it:

    with it.having('something'):

        @it.should("do stuff")
        def test_should_do_stuff(case):
            pass

    it.createTests(globals())