File: boolean_vows.py

package info (click to toggle)
pyvows 3.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 500 kB
  • sloc: python: 3,884; makefile: 19; sh: 8
file content (114 lines) | stat: -rw-r--r-- 2,968 bytes parent folder | download | duplicates (4)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# pyvows testing engine
# https://github.com/heynemann/pyvows

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Bernardo Heynemann heynemann@gmail.com

from pyvows import Vows, expect


@Vows.batch
class AssertionIsTrue(Vows.Context):

    class WhenBoolean(Vows.Context):
        def topic(self):
            return True

        def we_can_assert_it_is_true(self, topic):
            expect(topic).to_be_true()

    class WhenNumber(Vows.Context):
        def topic(self):
            return 1

        def we_can_assert_number_is_true(self, topic):
            expect(topic).to_be_true()

    class WhenString(Vows.Context):
        def topic(self):
            return 'some'

        def we_can_assert_string_is_true(self, topic):
            expect(topic).to_be_true()

    class WhenList(Vows.Context):
        def topic(self):
            return ['some']

        def we_can_assert_list_is_true(self, topic):
            expect(topic).to_be_true()

    class WhenDict(Vows.Context):
        def topic(self):
            return {'some': 'key'}

        def we_can_assert_dict_is_true(self, topic):
            expect(topic).to_be_true()

    class WhenWeGetAnError(Vows.Context):

        @Vows.capture_error
        def topic(self, last):
            expect(False).to_be_true()

        def we_get_an_understandable_message(self, topic):
            expect(topic).to_have_an_error_message_of("Expected topic(False) to be truthy")


@Vows.batch
class AssertionIsFalse(Vows.Context):

    class WhenBoolean(Vows.Context):
        def topic(self):
            return False

        def we_can_assert_it_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenNumber(Vows.Context):
        def topic(self):
            return 0

        def we_can_assert_zero_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenNone(Vows.Context):
        def topic(self):
            return None

        def we_can_assert_none_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenString(Vows.Context):
        def topic(self):
            return ''

        def we_can_assert_empty_string_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenList(Vows.Context):
        def topic(self):
            return []

        def we_can_assert_empty_list_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenDict(Vows.Context):
        def topic(self):
            return {}

        def we_can_assert_empty_dict_is_false(self, topic):
            expect(topic).to_be_false()

    class WhenWeGetAnError(Vows.Context):

        @Vows.capture_error
        def topic(self):
            expect(True).to_be_false()

        def we_get_an_understandable_message(self, topic):
            expect(topic).to_have_an_error_message_of("Expected topic(True) to be falsy")