Beispiel #1
0
class TestSubscope(unittest.TestCase):
    def setUp(self):
        self.subscope = Subscope()

    def test_sources_member_is_created(self):
        self.assertIsInstance(self.subscope.sources, dict)
        # sources are all present
        self.assertEquals(sorted(self.subscope.sources.keys()),
                          sorted(SubscopeSource.REGISTRY))

    def test_search(self):
        # mock the sources
        srcs = {}
        for name, search_return in [('src1', [{}]), ('src2', [{}, {}])]:
            src = Mock()
            src.name.return_value = name
            src.search.return_value = search_return
            srcs[name] = src
        self.subscope.sources = srcs

        result = self.subscope.search('/path/to/movie', ['en'])

        srcs['src1'].search.assert_called_with('/path/to/movie', ['en'])
        srcs['src2'].search.assert_called_with('/path/to/movie', ['en'])

        expected = [{
            'moviepath': '/path/to/movie',
            'source': 'src2',
            'ext': '.srt'
        }, {
            'moviepath': '/path/to/movie',
            'source': 'src2',
            'ext': '.srt'
        }, {
            'moviepath': '/path/to/movie',
            'source': 'src1',
            'ext': '.srt'
        }]
        self.assertEquals(sorted(sorted(r.items()) for r in result),
                          sorted(sorted(r.items()) for r in expected))

    def test_download(self):
        tempdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tempdir)

        def do_download(sub, stream):
            stream.write(b'this is my sub')

        self.subscope.sources = \
            {'test': Mock(download=Mock(side_effect=do_download))}

        path = os.path.join(tempdir, 'my-movie.avi')
        self.subscope.download({
            'source': 'test',
            'moviepath': path,
            'ext': '.srt'
        })

        with open(os.path.join(tempdir, 'my-movie.srt')) as f:
            self.assertEquals(f.read(), 'this is my sub')
Beispiel #2
0
class TestSubscope(unittest.TestCase):
    def setUp(self):
        self.subscope = Subscope()

    def test_sources_member_is_created(self):
        self.assertIsInstance(self.subscope.sources, dict)
        # sources are all present
        self.assertEquals(sorted(self.subscope.sources.keys()),
                          sorted(SubscopeSource.REGISTRY))

    def test_search(self):
        # mock the sources
        srcs = {}
        for name, search_return in [('src1', [{}]),
                                    ('src2', [{}, {}])]:
            src = Mock()
            src.name.return_value = name
            src.search.return_value = search_return
            srcs[name] = src
        self.subscope.sources = srcs

        result = self.subscope.search('/path/to/movie', ['en'])

        srcs['src1'].search.assert_called_with('/path/to/movie', ['en'])
        srcs['src2'].search.assert_called_with('/path/to/movie', ['en'])

        expected = [
            {'moviepath': '/path/to/movie', 'source': 'src2', 'ext': '.srt'},
            {'moviepath': '/path/to/movie', 'source': 'src2', 'ext': '.srt'},
            {'moviepath': '/path/to/movie', 'source': 'src1', 'ext': '.srt'}]
        self.assertEquals(sorted(sorted(r.items()) for r in result),
                          sorted(sorted(r.items()) for r in expected))

    def test_download(self):
        tempdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tempdir)

        def do_download(sub, stream):
            stream.write(b'this is my sub')

        self.subscope.sources = \
            {'test': Mock(download=Mock(side_effect=do_download))}

        path = os.path.join(tempdir, 'my-movie.avi')
        self.subscope.download({'source': 'test', 'moviepath': path,
                                'ext': '.srt'})

        with open(os.path.join(tempdir, 'my-movie.srt')) as f:
            self.assertEquals(f.read(), 'this is my sub')
Beispiel #3
0
def main(argv=None):
    logging.basicConfig()

    defaults = read_conf(os.path.expanduser('~/.subscope.cfg'))

    options = parse_args(argv, **defaults)
    LOG.setLevel(getattr(logging, options.log_level.upper()))

    check_pypi_version()

    subscope = Subscope()

    set_requests_global_defaults('get', timeout=options.requests_timeout)
    set_requests_global_defaults('post', timeout=options.requests_timeout)

    if options.interactive:
        handler_klass = DownloadInteractiveHandler
    else:
        handler_klass = DownloadFirstHandler
    handler = handler_klass(subscope, force=options.force)
    try:
        handler.run(options.filepaths, options.language.split(','))
    except KeyboardInterrupt:
        sys.exit("\nInterrupted.")
Beispiel #4
0
 def setUp(self):
     self.subscope = Subscope()
Beispiel #5
0
 def setUp(self):
     self.subscope = Subscope()