コード例 #1
0
ファイル: test_core.py プロジェクト: dsdshcym/subscope
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')
コード例 #2
0
ファイル: test_core.py プロジェクト: dsdshcym/subscope
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')
コード例 #3
0
ファイル: main.py プロジェクト: dsdshcym/subscope
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.")
コード例 #4
0
ファイル: test_core.py プロジェクト: dsdshcym/subscope
 def setUp(self):
     self.subscope = Subscope()
コード例 #5
0
ファイル: test_core.py プロジェクト: dsdshcym/subscope
 def setUp(self):
     self.subscope = Subscope()