コード例 #1
0
    def test_1(self):
        with patch('man.Watch') as mock_watch:
            mock_dt = MagicMock()
            mock_dt.strftime.return_value = '01:05 pm'
            mock_watch.return_value.get_time.return_value = mock_dt

            man = Man()
            self.assertEqual(man.tell_time(), 'It is now 01:05 pm')
            mock_dt.strftime.assert_called_once_with('%I:%M %p')
コード例 #2
0
    def test_1(self, mock_watch):
        # Create a fake datetime object
        mock_dt = MagicMock()
        mock_dt.strftime.return_value = '01:05 pm'

        # Have watch always return that fake object
        mock_watch.return_value.get_time.return_value = mock_dt

        man = Man()
        self.assertEquals(man.tell_time(), 'It is now 01:05 pm')
        mock_dt.strftime.assert_called_once_with('%I:%M %p')
コード例 #3
0
class Foo(unittest.TestCase):

    def test_1(self):
        self.man = Man()
        print self.man.tell_time()