예제 #1
0
 def test_add__without_captured_data(self):
     captured1 = Captured()
     captured2 = Captured("STDOUT", "STDERR", "LOG_OUTPUT")
     captured1.add(captured2)
     assert captured1.stdout == "STDOUT"
     assert captured1.stderr == "STDERR"
     assert captured1.log_output == "LOG_OUTPUT"
예제 #2
0
    def test_add__with_captured_data(self):
        captured1 = Captured("stdout1", "stderr1", "log_output1")
        captured2 = Captured("STDOUT2", "STDERR2", "LOG_OUTPUT2")

        captured1.add(captured2)
        assert captured1.stdout == "stdout1\nSTDOUT2"
        assert captured1.stderr == "stderr1\nSTDERR2"
        assert captured1.log_output == "log_output1\nLOG_OUTPUT2"
예제 #3
0
    def test_make_report__should_only_contain_nonempty_data_sections(self):
        captured1 = Captured(stdout="xxx")
        expected = "Captured stdout:\nxxx"
        assert captured1.make_report() == expected

        captured2 = Captured(stderr="yyy")
        expected = "Captured stderr:\nyyy"
        assert captured2.make_report() == expected

        captured3 = Captured(log_output="zzz")
        expected = "Captured logging:\nzzz"
        assert captured3.make_report() == expected
예제 #4
0
    def test_operator_iadd(self):
        captured1 = Captured("stdout1", "stderr1", "log_output1")
        captured2 = Captured("STDOUT2", "STDERR2", "LOG_OUTPUT2")

        captured1 += captured2
        assert captured1.stdout == "stdout1\nSTDOUT2"
        assert captured1.stderr == "stderr1\nSTDERR2"
        assert captured1.log_output == "log_output1\nLOG_OUTPUT2"
        # -- ENSURE: captured2 is not modified.
        assert captured2.stdout == "STDOUT2"
        assert captured2.stderr == "STDERR2"
        assert captured2.log_output == "LOG_OUTPUT2"
예제 #5
0
 def test_reset(self):
     captured = Captured("STDOUT", "STDERR", "LOG_OUTPUT")
     captured.reset()
     assert captured.stdout == u""
     assert captured.stderr == u""
     assert captured.log_output == u""
     assert not captured
예제 #6
0
    def test_ctor_with_params(self):
        captured = Captured(u"STDOUT", u"STDERR", u"LOG_OUTPUT")
        assert captured.stdout == u"STDOUT"
        assert captured.stderr == u"STDERR"
        assert captured.log_output == u"LOG_OUTPUT"

        captured = Captured(stdout=u"STDOUT")
        assert captured.stdout == u"STDOUT"
        assert captured.stderr == u""
        assert captured.log_output == u""

        captured = Captured(stderr=u"STDERR")
        assert captured.stdout == u""
        assert captured.stderr == u"STDERR"
        assert captured.log_output == u""

        captured = Captured(log_output=u"LOG_OUTPUT")
        assert captured.stdout == u""
        assert captured.stderr == u""
        assert captured.log_output == u"LOG_OUTPUT"
예제 #7
0
    def test_make_report__with_all_sections(self):
        captured = Captured(stdout="xxx", stderr="yyy", log_output="zzz")
        expected = """\
Captured stdout:
xxx

Captured stderr:
yyy

Captured logging:
zzz"""
        assert captured.make_report() == expected
예제 #8
0
 def __init__(self, filename, line, keyword, name):
     filename = filename or '<string>'
     filename = os.path.relpath(filename, os.getcwd())  # -- NEEDS: abspath?
     self.location = FileLocation(filename, line)
     assert isinstance(keyword, six.text_type)
     assert isinstance(name, six.text_type)
     self.keyword = keyword
     self.name = name
     # -- SINCE: 1.2.6
     self.captured = Captured()
     # -- ERROR CONTEXT INFO:
     self.exception = None
     self.exc_traceback = None
     self.error_message = None
예제 #9
0
 def __init__(self, filename, line, keyword, name):
     filename = filename or '<string>'
     try:
         filename = os.path.relpath(filename, os.getcwd())   # -- NEEDS: abspath?
     except ValueError:
         # On Windows a relative path can't be evaluated for
         # paths on two different drives (i.e. c:\foo and f:\bar).
         # The only thing left to is to use the original absolute
         # path.
         filename = filename
     self.location = FileLocation(filename, line)
     assert isinstance(keyword, six.text_type)
     assert isinstance(name, six.text_type)
     self.keyword = keyword
     self.name = name
     # -- SINCE: 1.2.6
     self.captured = Captured()
     # -- ERROR CONTEXT INFO:
     self.exception = None
     self.exc_traceback = None
     self.error_message = None
예제 #10
0
 def test_bool_conversion__returns_false_without_captured_output(self):
     captured = Captured()
     assert bool(captured) == False
예제 #11
0
 def test_default_ctor(self):
     captured = Captured()
     assert captured.stdout == u""
     assert captured.stderr == u""
     assert captured.log_output == u""
     assert not captured
예제 #12
0
 def test_output__contains_concatenated_parts(self, params, expected):
     captured = Captured(**params)
     assert captured.output == expected
예제 #13
0
 def test_bool_conversion__returns_true_with_captured_output(self, params):
     captured = Captured(**params)
     assert bool(captured)