Example #1
0
    def test_fix_without_confirmation(self):
        item = self.addIntegrityFailFixture()

        with self.assertRaises(SystemExit), captureLog() as logs:
            beets.ui._raw_main(['check', '-e'])
        self.assertIn('WARNING It seems that file is truncated',
                      '\n'.join(logs))

        with captureLog() as logs:
            beets.ui._raw_main(['check', '--fix', '--force'])
        self.assertIn(item.path.decode('utf-8'), '\n'.join(logs))

        with captureLog() as logs:
            beets.ui._raw_main(['check', '-e'])
        self.assertNotIn('WARNING It seems that file is truncated',
                         '\n'.join(logs))
Example #2
0
    def test_shellquote(self):
        item = self.lib.items([u'ok.flac']).get()
        item['title'] = "ok's"
        item.move()

        with captureLog() as logs:
            beets.ui._raw_main(['check', '--external', item.title])
        self.assertNotIn('WARNING', '\n'.join(logs))
Example #3
0
    def test_fix_integrity(self):
        item = self.addIntegrityFailFixture()

        with self.assertRaises(SystemExit), captureLog() as logs:
            beets.ui._raw_main(['check', '-e'])
        self.assertIn('WARNING It seems that file is truncated',
                      '\n'.join(logs))

        with controlStdin(u'y'), captureLog() as logs:
            beets.ui._raw_main(['check', '--fix'])
        self.assertIn(item.path.decode('utf-8'), '\n'.join(logs))
        self.assertIn('FIXED: {}'.format(item.path.decode('utf-8')),
                      '\n'.join(logs))

        with captureLog() as logs:
            beets.ui._raw_main(['check', '-e'])
        self.assertNotIn('WARNING It seems that file is truncated',
                         '\n'.join(logs))
Example #4
0
    def test_ogg_vorbis_integrity(self):
        item = self.lib.items(u'truncated.ogg').get()

        with self.assertRaises(SystemExit):
            with captureLog() as logs:
                beets.ui._raw_main(['check', '--external'])
                self.assertIn(
                    u'check: WARNING non-zero exit code for oggz-validate: {}'.
                    format(item.path), logs)
Example #5
0
    def test_update_nonexistent(self):
        item = Item(path='/doesnotexist')
        self.lib.add(item)

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

        self.assertIn('ERROR [Errno 2] No such file or directory',
                      '\n'.join(logs))
Example #6
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 #7
0
    def test_log_error_for_invalid_checksum(self):
        item = self.lib.items(u'ok').get()
        verify_checksum(item)
        self.modifyFile(item.path)

        with captureLog() as logs:
            beets.ui._raw_main(['write', item.title])
        self.assertRegexpMatches(
            '\n'.join(logs),
            r'error reading .*: checksum did not match value in library')
Example #8
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 #9
0
    def test_flac_integrity(self):
        item = self.lib.items(u'truncated.flac').get()

        with self.assertRaises(SystemExit):
            with captureLog() as logs:
                beets.ui._raw_main(['check', '--external'])
        print('\n'.join(logs))
        self.assertIn(
            u'check: WARNING while decoding data: {}'.format(
                item.path.decode('utf-8')), logs)
Example #10
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 #11
0
    def test_dont_fix_with_wrong_checksum(self):
        item = self.addIntegrityFailFixture()
        item['checksum'] = 'this is wrong'
        item.store()

        with captureLog() as logs:
            beets.ui._raw_main(['check', '--fix', '--force'])
        self.assertIn('FAILED checksum', '\n'.join(logs))

        item.load()
        self.assertEqual(item['checksum'], 'this is wrong')
Example #12
0
    def test_mp3_integrity(self):
        item = self.lib.items([u'path::truncated.mp3']).get()

        with self.assertRaises(SystemExit):
            with captureLog() as logs:
                beets.ui._raw_main(['check', '--external'])
        print('\n'.join(logs))
        self.assertIn(
            u'check: WARNING It seems that file is '
            'truncated or there is garbage at the '
            'end of the file: {}'.format(item.path.decode('utf-8')), logs)
Example #13
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 #14
0
    def test_check_failed_error_log(self):
        self.setupFixtureLibrary()
        item = self.lib.items().get()
        self.modifyFile(item.path)

        try:
            with captureLog('beets.check') as logs:
                beets.ui._raw_main(['check'])
        except SystemExit:
            pass

        self.assertIn('FAILED: {}'.format(item.path.decode('utf-8')),
                      '\n'.join(logs))
Example #15
0
    def test_not_found_error_log(self):
        self.setupFixtureLibrary()
        item = self.lib.items().get()
        item.path = '/doesnotexist'
        item.store()

        try:
            with captureLog('beets.check') as logs:
                beets.ui._raw_main(['check'])
        except SystemExit:
            pass

        self.assertIn("OK:", '\n'.join(logs))
        self.assertIn('ERROR [Errno 2] No such file or directory',
                      '\n'.join(logs))