File: test_boolean.py

package info (click to toggle)
preggy 1.4.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 408 kB
  • sloc: python: 1,929; makefile: 22; sh: 8
file content (92 lines) | stat: -rw-r--r-- 1,885 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
# -*- coding: utf-8 -*-

# preggy assertions
# https://github.com/heynemann/preggy

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

from preggy import expect

#-----------------------------------------------------------------------------

EXPECTED_TEST_DATA = (
    True,
    'qwe',
    1,
    [1],
    tuple([1]),
    {'a': 'b'}
)

NOT_EXPECTED_TEST_DATA = (
    False,
    '',
    0,
    [],
    tuple([]),
    {}
)

#-----------------------------------------------------------------------------

def is_true(item):
    expect(item).to_be_true()
    try:
        expect(item).not_to_be_true()
    except AssertionError:
        return
    assert False, 'Should not have gotten this far'


def is_not_true(item):
    expect(item).Not.to_be_true()
    expect(item).not_to_be_true()

    try:
        expect(item).to_be_true()
    except AssertionError:
        return
    assert False, 'Should not have gotten this far'


def is_false(item):
    expect(item).to_be_false()
    try:
        expect(item).not_to_be_false()
    except AssertionError:
        return
    assert False, 'Should not have gotten this far'


def is_not_false(item):
    expect(item).Not.to_be_false()
    expect(item).not_to_be_false()

    try:
        expect(item).to_be_false()
    except AssertionError:
        return
    assert False, 'Should not have gotten this far'

#-----------------------------------------------------------------------------

def test_to_be_true():
    for item in EXPECTED_TEST_DATA:
        is_true(item)


def test_not_to_be_true():
    for item in NOT_EXPECTED_TEST_DATA:
        is_not_true(item)


def test_to_be_false():
    for item in NOT_EXPECTED_TEST_DATA:
        is_false(item)


def test_not_to_be_false():
    for item in EXPECTED_TEST_DATA:
        is_not_false(item)