コード例 #1
0
ファイル: test_camgrab.py プロジェクト: takeontom/camgrab
    def test_should_save_image(self):
        good_grabber = Grabber('http://example.com')

        good_grabber.save = True
        good_grabber.save_filename = 'some_filename'
        good_grabber.save_dir = 'some_dir'
        assert good_grabber.should_save_image() is True

        no_save_grabber = Grabber('http://example.com')
        no_save_filename_grabber = Grabber('http://example.com')
        no_save_dir_grabber = Grabber('http://example.com')

        no_save_grabber.save = False
        no_save_grabber.save_filename = 'some_filename'
        no_save_grabber.save_dir = 'some_dir'

        no_save_filename_grabber.save = True
        no_save_filename_grabber.save_filename = None
        no_save_filename_grabber.save_dir = 'some_dir'

        no_save_dir_grabber.save = True
        no_save_dir_grabber.save_filename = 'some_filename'
        no_save_dir_grabber.save_dir = None

        bad_grabbers = (no_save_grabber, no_save_dir_grabber,
                        no_save_filename_grabber)
        for grabber in bad_grabbers:
            assert grabber.should_save_image() is False
コード例 #2
0
ファイル: test_camgrab.py プロジェクト: takeontom/camgrab
    def test_get_save_path(self, mocker):
        mocked_datetime = mocker.patch('camgrab.camgrab.datetime',
                                       autospec=True)
        fake_datetime = datetime(2017, 1, 2, 12, 13, 14, 987654)
        mocked_datetime.now = mocker.Mock(return_value=fake_datetime)

        grabber = Grabber('http://example.com')
        grabber.save_dir = 'a_dir'
        grabber.save_filename = '{Y}{m}{d}/blah/{H}{M}{S}{f}.jpg'

        expected = 'a_dir/{Y}{m}{d}/blah/{H}{M}{S}{f}.jpg'

        grabber.format_path = mocker.Mock(grabber.format_path,
                                          autospec=True,
                                          return_value=expected)

        full_save_path = grabber.get_save_path()
        assert full_save_path == expected