Example #1
0
def not_raising():
    """Assert.not_raising"""

    with Assert.raises(AssertionError):
        with Assert.not_raising(RuntimeError):
            raise RuntimeError

    try:
        with Assert.not_raising(RuntimeError):
            pass
    except Exception:
        raise AssertionError("failed despite not raising RuntimeError")
Example #2
0
def run():
    """Tests().run"""

    col = Tests()

    @col.test
    def fail():
        assert 1 == 2

    @col.test
    def succeed():
        assert 1 == 1

    @col.test
    def exit():
        raise SystemExit

    result = TestReporter()
    with Assert.not_raising(SystemExit):
        col.run(result)

    assert len(result.failed) == 2
    assert len(result.succeeded) == 1

    assert result.failed[0].test.__wrapped__ is fail
    assert result.failed[0].exc_info[0] is TestFailure
    assert result.succeeded[0].test.__wrapped__ is succeed
Example #3
0
def run():
    """Tests().run"""

    col = Tests()

    @col.test
    def fail():
        assert 1 == 2

    @col.test
    def succeed():
        assert 1 == 1

    @col.test
    def exit():
        raise SystemExit

    result = TestReporter()
    with Assert.not_raising(SystemExit):
        col.run(result)

    assert len(result.failed) == 2
    assert len(result.succeeded) == 1

    assert result.failed[0].test.__wrapped__ is fail
    assert result.failed[0].exc_info[0] is TestFailure
    assert result.succeeded[0].test.__wrapped__ is succeed
Example #4
0
    def wait(self):
        aresult = AsyncResult()

        def setter(aresult):
            time.sleep(1)
            aresult.set('foo')
        t = Thread(target=setter, args=(aresult, ))
        t.start()
        with Assert.not_raising(TimeoutError):
            aresult.wait(2)
Example #5
0
 def get_dimensions(self):
     with Assert.raises(NotImplementedError):
         self.writer.get_dimensions()
     writer = TerminalWriter(sys.__stdout__)
     with Assert.not_raising(NotImplementedError):
         dimensions = writer.get_dimensions()
     height, width = dimensions
     Assert.isinstance(height, int)
     Assert.isinstance(width, int)
     Assert(height) == dimensions.height
     Assert(width) == dimensions.width
Example #6
0
 def get_dimensions(self):
     with Assert.raises(NotImplementedError):
         self.writer.get_dimensions()
     writer = TerminalWriter(sys.__stdout__)
     with Assert.not_raising(NotImplementedError):
         dimensions = writer.get_dimensions()
     height, width = dimensions
     Assert.isinstance(height, int)
     Assert.isinstance(width, int)
     Assert(height) == dimensions.height
     Assert(width) == dimensions.width
Example #7
0
    def init(self):
        writer = TerminalWriter(StringIO())
        progressbar = ProgressBar([], writer, maxsteps=20)
        widget = StepWidget()
        Assert(widget.init(progressbar, writer.get_width())) == '0 of 20'
        Assert(widget.size_hint(progressbar)) == 7

        with Assert.raises(ValueError):
            StepWidget('foo')

        with Assert.not_raising(ValueError):
            StepWidget('bytes')
Example #8
0
    def init(self):
        writer = TerminalWriter(StringIO())
        progressbar = ProgressBar([], writer, maxsteps=20)
        widget = StepWidget()
        Assert(widget.init(progressbar, writer.get_width())) == '0 of 20'
        Assert(widget.size_hint(progressbar)) == 7

        with Assert.raises(ValueError):
            StepWidget('foo')

        with Assert.not_raising(ValueError):
            StepWidget('bytes')
Example #9
0
    def get_width(self):
        with Assert.not_raising(Exception):
            self.writer.get_width()
        writer = TerminalWriter(sys.__stdout__)
        Assert(writer.get_width()) == writer.get_dimensions()[1]

        writer = TerminalWriter(StringIO())
        os.environ['COLUMNS'] = '50'
        Assert(writer.get_width()) == 50
        del os.environ['COLUMNS']
        Assert(writer.get_width()) == TerminalWriter.default_width
        default_width = TerminalWriter.default_width
        Assert(writer.get_width(default_width + 1)) == default_width + 1
Example #10
0
    def get_width(self):
        with Assert.not_raising(Exception):
            self.writer.get_width()
        writer = TerminalWriter(sys.__stdout__)
        Assert(writer.get_width()) == writer.get_dimensions()[1]

        writer = TerminalWriter(StringIO())
        os.environ['COLUMNS'] = '50'
        Assert(writer.get_width()) == 50
        del os.environ['COLUMNS']
        Assert(writer.get_width()) == TerminalWriter.default_width
        default_width = TerminalWriter.default_width
        Assert(writer.get_width(default_width + 1)) == default_width + 1
Example #11
0
    def get(self):
        aresult = AsyncResult()

        with Assert.raises(TimeoutError):
            aresult.get(0.1)

        def setter(aresult):
            time.sleep(1)
            aresult.set('foo')
        t = Thread(target=setter, args=(aresult, ))
        t.start()
        with Assert.not_raising(TimeoutError):
            Assert(aresult.get(2)) == 'foo'

        aresult.set('foo')
        Assert(aresult.get()) == 'foo'

        aresult = AsyncResult()
        aresult.set(ValueError(), success=False)
        with Assert.raises(ValueError):
            aresult.get()