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)
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())
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))
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))
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')
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)
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)
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')