コード例 #1
0
    def test_restart(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                if input == 'quit':
                    raise SystemExit

        scenario = '''
>>> quit
--- not running
--- restart
--- running
--- restart
--- running
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 6
        self.assert_line(lines, 1, Input, 'quit')
        self.assert_line(lines, 2, Meta, 'not running')
        self.assert_line(lines, 3, Meta, 'restart')
        self.assert_line(lines, 4, Meta, 'running')
        self.assert_line(lines, 5, Meta, 'restart')
        self.assert_line(lines, 6, Meta, 'running')

        # this should not trigger any asserts
        scenario_tester.test(scenario)
コード例 #2
0
ファイル: test_scenario_tester.py プロジェクト: bebraw/nixtu
    def test_input_fail(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                pass

        scenario = '''
fail
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 1
        self.assert_line(lines, 1, Output, 'fail')

        raises(InputError, scenario_tester.test, scenario)
コード例 #3
0
    def test_not_running_fail(self):
        class Application(AbstractApplication):
            pass

        scenario = '''
>>> a = 5
--- not running
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 2
        self.assert_line(lines, 1, Input, 'a = 5')
        self.assert_line(lines, 2, Meta, 'not running')

        raises(RunningError, scenario_tester.test, scenario)
コード例 #4
0
ファイル: test_scenario_tester.py プロジェクト: bebraw/nixtu
    def test_output_fail(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                return 42

        scenario = '''
>>> fail
>>> fail
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 2
        self.assert_line(lines, 1, Input, 'fail')
        self.assert_line(lines, 2, Input, 'fail')

        raises(OutputError, scenario_tester.test, scenario)
コード例 #5
0
ファイル: test_scenario_tester.py プロジェクト: bebraw/nixtu
    def test_match_fail(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                if input == 'a':
                    return 42

        scenario = '''
>>> a = 4
>>> a
5
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 3
        self.assert_line(lines, 1, Input, 'a = 4')
        self.assert_line(lines, 2, Input, 'a')
        self.assert_line(lines, 3, Output, '5')

        raises(MatchError, scenario_tester.test, scenario)
コード例 #6
0
ファイル: test_scenario_tester.py プロジェクト: bebraw/nixtu
    def test_ellipsis(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                if input == 'a':
                    return 5

        scenario = '''
>>> a = 5
>>> a
...
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 3
        self.assert_line(lines, 1, Input, 'a = 5')
        self.assert_line(lines, 2, Input, 'a')
        self.assert_line(lines, 3, EllipsisOutput, None)

        scenario_tester.test(scenario)
コード例 #7
0
ファイル: test_scenario_tester.py プロジェクト: bebraw/nixtu
    def test_passing_test(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                if input == 'a':
                    return 4

        scenario = '''
>>> a = 4
>>> a
4
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 3
        self.assert_line(lines, 1, Input, 'a = 4')
        self.assert_line(lines, 2, Input, 'a')
        self.assert_line(lines, 3, Output, '4')

        # this should not trigger any asserts
        scenario_tester.test(scenario)
コード例 #8
0
    def test_running(self):
        class Application(AbstractApplication):
            pass
        
        scenario = '''
>>> a = 4
--- running
>>> b = 5
--- running
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 4
        self.assert_line(lines, 1, Input, 'a = 4')
        self.assert_line(lines, 2, Meta, 'running')
        self.assert_line(lines, 3, Input, 'b = 5')
        self.assert_line(lines, 4, Meta, 'running')

        # this should not trigger any asserts
        scenario_tester.test(scenario)
コード例 #9
0
    def test_running_fail(self):
        class Application(AbstractApplication):
            def interpret(self, input):
                if input == 'quit':
                    raise SystemExit

        scenario = '''
>>> a = 4
--- running
>>> quit
--- running
'''

        scenario_tester = ScenarioTester(Application)
        scenario_tester.parse(scenario)
        lines = scenario_tester.lines

        assert len(lines) == 4
        self.assert_line(lines, 1, Input, 'a = 4')
        self.assert_line(lines, 2, Meta, 'running')
        self.assert_line(lines, 3, Input, 'quit')
        self.assert_line(lines, 4, Meta, 'running')

        raises(NotRunningError, scenario_tester.test, scenario)