def test_close(self, serial): driver = Driver().open('PORTNAME') driver.close() assert_that(serial().close, called()) assert_that(driver._serial, is_(None))
def test_called_ok(): matcher = called() mock = Mock() mock() ok = matcher.matches(mock) assert_that(ok, equal_to(True))
def test_called_fail(desc): expected = 'was called 0 times' matcher = called() mock = Mock() ok = matcher.matches(mock, desc) assert_that(ok, equal_to(False)) assert_that(str(desc), equal_to(expected))
def test_called_fail(): expected = ''' Expected: Mock called with ANYTHING None times but: was called 0 times ''' mock = Mock() with assert_raises(AssertionError) as e: assert_that(mock, called()) assert_that(str(e.exception), equal_to(expected))
def test_open(self, serial): driver = Driver().open('PORTNAME') assert_that(serial, called()) assert_that(driver._serial, is_(serial()))
def test_called_ok_twice(): mock = Mock() mock() mock() assert_that(mock, called())
def test_called_description(desc): expected = 'Mock called a value greater than <0> times with ANYTHING' matcher = called() matcher.describe_to(desc) assert_that(str(desc), equal_to(expected))