Example #1
0
    def test_check_failed_exit_code(self):
        MockChecker.install()
        self.addIntegrityFailFixture()

        with self.assertRaises(SystemExit) as exit:
            beets.ui._raw_main(['check', '--external'])
        self.assertEqual(exit.exception.code, 15)
Example #2
0
    def test_no_integrity_checkers_warning(self):
        MockChecker.installNone()
        self.addIntegrityFailFixture()

        with self.assertRaises(UserError) as error:
            beets.ui._raw_main(['check', '--external'])

        self.assertIn('No integrity checkers found.', error.exception.args[0])
Example #3
0
    def test_print_integrity_checkers(self):
        MockChecker.install()
        self.addIntegrityFailFixture()

        with self.assertRaises(SystemExit):
            with captureStdout() as stdout:
                beets.ui._raw_main(['check', '--external'])

        self.assertIn('Using integrity checker mock', stdout.getvalue())
Example #4
0
    def test_integrity_warning(self):
        MockChecker.install()
        self.addIntegrityFailFixture()

        with self.assertRaises(SystemExit):
            with captureLog() as logs:
                beets.ui._raw_main(['check', '--external'])

        self.assertIn('WARNING file is corrupt', '\n'.join(logs))
Example #5
0
    def test_add_shows_integrity_warning(self):
        MockChecker.install()
        item = self.addIntegrityFailFixture(checksum=False)

        with captureLog() as logs:
            beets.ui._raw_main(['check', '-a'])

        self.assertIn(
            'WARNING file is corrupt: {}'.format(item.path.decode('utf-8')),
            '\n'.join(logs))
Example #6
0
    def test_add_corrupt_files(self):
        MockChecker.install()
        self.setupImportDir(['ok.mp3', 'truncated.mp3'])

        with self.mockAutotag(), controlStdin('n'):
            beets.ui._raw_main(['import', self.import_dir])

        self.assertEqual(len(self.lib.items()), 2)
        item = self.lib.items(u'truncated').get()
        mediafile = MediaFile(item.path)
        self.assertEqual(mediafile.title, 'truncated tag')
Example #7
0
    def test_quiet_skip_corrupt_files(self):
        MockChecker.install()
        self.setupImportDir(['ok.mp3', 'truncated.mp3'])

        with self.mockAutotag(), captureLog() as logs:
            beets.ui._raw_main(['import', '-q', self.import_dir])

        self.assertIn('check: Warning: failed to verify integrity', logs)
        self.assertIn('truncated.mp3: file is corrupt\ncheck: Skipping.',
                      '\n'.join(logs))
        self.assertEqual(len(self.lib.items()), 0)
Example #8
0
    def test_skip_corrupt_files(self):
        MockChecker.install()
        self.setupImportDir(['ok.mp3', 'truncated.mp3'])

        with self.mockAutotag(), controlStdin(' '), \
                captureStdout() as stdout, captureLog() as logs:
            beets.ui._raw_main(['import', self.import_dir])

        self.assertIn('check: Warning: failed to verify integrity', logs)
        self.assertIn('truncated.mp3: file is corrupt', '\n'.join(logs))
        self.assertIn('Do you want to skip this album', stdout.getvalue())
        self.assertEqual(len(self.lib.items()), 0)
Example #9
0
    def test_write_on_integrity_error(self):
        MockChecker.install()

        item = self.lib.items(u'truncated').get()

        item['title'] = 'newtitle'
        item.store()
        beets.ui._raw_main(['write', item.title])

        item.load()
        verify_checksum(item)
        mediafile = MediaFile(item.path)
        self.assertEqual(mediafile.title, 'newtitle')
Example #10
0
 def tearDown(self):
     super(ImportTest, self).tearDown()
     MockChecker.restore()