File: classes_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 (55 lines) | stat: -rw-r--r-- 1,560 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
#!/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


class SomeClass(object):
    pass


class OtherClass(object):
    pass


@Vows.batch
class AssertionIsInstance(Vows.Context):
    def topic(self):
        return SomeClass()

    class WhenIsInstance(Vows.Context):

        def we_get_an_instance_of_someclass(self, topic):
            expect(topic).to_be_instance_of(SomeClass)

        class WhenWeGetAnError(Vows.Context):

            @Vows.capture_error
            def topic(self, last):
                expect(2).to_be_instance_of(str)

            def we_get_an_understandable_message(self, topic):
                msg = 'Expected topic(2) to be an instance of {0!r}, but it was a {1!r}'.format(str, int)
                expect(topic).to_have_an_error_message_of(msg)

    class WhenIsNotInstance(Vows.Context):

        def we_do_not_get_an_instance_of_otherclass(self, topic):
            expect(topic).Not.to_be_instance_of(OtherClass)

        class WhenWeGetAnError(Vows.Context):

            @Vows.capture_error
            def topic(self, last):
                expect(2).not_to_be_instance_of(int)

            def we_get_an_understandable_message(self, topic):
                expect(topic).to_have_an_error_message_of(
                    'Expected topic(2) not to be an instance of {0!s}'.format(int))