Completed
Pull Request — master (#70)
by
unknown
01:14
created

src.hamcrest.core.StringDescription   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %
Metric Value
dl 0
loc 15
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A StringDescription.__str__() 0 3 1
A StringDescription.append() 0 2 1
A StringDescription.__init__() 0 2 1
1
from __future__ import absolute_import
2
3
import codecs
4
import six
5
6
from .base_description import BaseDescription
7
8
__author__ = "Jon Reid"
9
__copyright__ = "Copyright 2011 hamcrest.org"
10
__license__ = "BSD, see License.txt"
11
12
13
def tostring(selfdescribing):
14
    """Returns the description of a
15
    :py:class:`~hamcrest.core.selfdescribing.SelfDescribing` object as a
16
    string.
17
18
    :param selfdescribing: The object to be described.
19
    :returns: The description of the object.
20
    """
21
    return str(StringDescription().append_description_of(selfdescribing))
22
23
24
class StringDescription(BaseDescription):
25
    """A :py:class:`~hamcrest.core.description.Description` that is stored as a
26
    string.
27
28
    """
29
30
    def __init__(self):
31
        self.out = ''
32
33
    def __str__(self):
34
        """Returns the description."""
35
        return self.out
36
37
    def append(self, string):
38
        self.out += six.text_type(string)
39