File: test_api.py

package info (click to toggle)
python-molotov 2.7-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,264 kB
  • sloc: python: 4,121; makefile: 60
file content (97 lines) | stat: -rw-r--r-- 2,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from molotov.api import get_scenarios, pick_scenario, scenario, setup
from molotov.tests.support import TestLoop, async_test


class TestUtil(TestLoop):
    def test_pick_scenario(self):
        @scenario(weight=10)
        async def _one(self):
            pass

        @scenario(weight=90)
        async def _two(self):
            pass

        picked = [pick_scenario()["name"] for i in range(100)]
        ones = len([f for f in picked if f == "_one"])
        self.assertTrue(ones < 20)

    @async_test
    async def test_can_call(self, loop, console, results):
        @setup()
        async def _setup(self):
            pass

        @scenario(weight=10)
        async def _one(self):
            pass

        # can still be called
        await _one(self)

        # same for fixtures
        await _setup(self)

    def test_default_weight(self):
        @scenario()
        async def _default_weight(self):
            pass

        self.assertEqual(len(get_scenarios()), 1)
        self.assertEqual(get_scenarios()[0]["weight"], 1)

    def test_no_scenario(self):
        @scenario(weight=0)
        async def _one(self):
            pass

        @scenario(weight=0)
        async def _two(self):
            pass

        self.assertEqual(get_scenarios(), [])

    def test_scenario_not_coroutine(self):
        try:

            @scenario(weight=1)
            def _one(self):
                pass

        except TypeError:
            return
        raise AssertionError("Should raise")

    def test_setup_not_coroutine(self):
        try:

            @setup()
            def _setup(self):
                pass

            @scenario(weight=90)
            async def _two(self):
                pass

        except TypeError:
            return
        raise AssertionError("Should raise")

    def test_two_fixtures(self):
        try:

            @setup()
            async def _setup(self):
                pass

            @setup()
            async def _setup2(self):
                pass

            @scenario(weight=90)
            async def _two(self):
                pass

        except ValueError:
            return
        raise AssertionError("Should raise")