示例#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, '\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))
示例#2
0
    def test_flac_integrity(self):
        item = self.lib.items('truncated.flac').get()

        with captureLog() as logs:
            beets.ui._raw_main(['check'])
        self.assertIn(
            'WARNING while decoding data: {}'.format(item.path), logs)
示例#3
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, '\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))
示例#4
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))
示例#5
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)
示例#6
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))
示例#7
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, '\n'.join(logs))
        self.assertIn('FIXED: {}'.format(item.path), '\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))
示例#8
0
    def test_ogg_vorbis_integrity(self):
        item = self.lib.items('truncated.ogg').get()

        with captureLog() as logs:
            beets.ui._raw_main(['check'])
        self.assertIn(
          'WARNING serialno 1038587646 missing *** eos: {}'.format(item.path),
          logs)
示例#9
0
    def test_mp3_integrity(self):
        item = self.lib.items(['path::truncated.mp3']).get()

        with captureLog() as logs:
            beets.ui._raw_main(['check'])
        self.assertIn('WARNING It seems that file is '
                      'truncated or there is garbage at the '
                      'end of the file: {}'.format(item.path), logs)
示例#10
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, '\n'.join(logs))
        self.assertIn('FIXED: {}'.format(item.path), '\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))
示例#11
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)
示例#12
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), logs)
示例#13
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))
示例#14
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),
                      '\n'.join(logs))
示例#15
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))
示例#16
0
    def test_log_error_for_invalid_checksum(self):
        item = self.lib.items('ok').get()
        check.verify(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')
示例#17
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), logs)
示例#18
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: '{}'"
                      .format(item.path), '\n'.join(logs))
示例#19
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),
                      '\n'.join(logs))
示例#20
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: '{}'".format(
                item.path), '\n'.join(logs))
示例#21
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), logs)
示例#22
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('Warning: failed to verify integrity', logs)
        self.assertIn('truncated.mp3: file is corrupt\nSkipping.', '\n'.join(logs))
        self.assertEqual(len(self.lib.items()), 0)
示例#23
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')
示例#24
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')
示例#25
0
    def test_check_failed_error_log(self):
        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), '\n'.join(logs))
示例#26
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), logs)
示例#27
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)
示例#28
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')
示例#29
0
    def test_add_shows_integrity_warning(self):
        MockChecker.install()

        item = self.lib.items('truncated').get()
        del item['checksum']
        item.store()

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

        self.assertIn('WARNING file is corrupt: {}'.format(item.path),
                      '\n'.join(logs))
    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)
示例#31
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), '\n'.join(logs))
示例#32
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)
示例#33
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: '{}'"
                      .format(item.path), '\n'.join(logs))
示例#34
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: '{}'".format(
                item.path), '\n'.join(logs))