Ejemplo n.º 1
0
 def test_adds_file_extension_to_pattern(self):
     cli.rename(['ANY_FILE.ANY_EXTENSION'], {
         '--dry': False,
         '--pattern': '<artist>'
     })
     self.mock_rename.assert_called_once_with('ANY_FILE.ANY_EXTENSION',
                                              'ANY_ARTIST.ANY_EXTENSION')
Ejemplo n.º 2
0
 def test_logs_if_wet_run(self):
     with logbook.TestHandler() as log_handler:
         cli.rename(['ANY_FILE.mp3'], {
             '--dry': False,
             '--pattern': '<artist>'
         })
         should_log = "Moving ANY_FILE.mp3 -> ANY_ARTIST.mp3"
         self.assertIn(should_log, log_handler.formatted_records[0])
Ejemplo n.º 3
0
 def test_operates_on_all_filenames(self):
     cli.rename(['FIRST_FILE.mp3', 'SECOND_FILE.flac'], {
         '--dry': False,
         '--pattern': '<artist>'
     })
     self.mock_rename.assert_has_calls([
         mock.call('FIRST_FILE.mp3', 'ANY_ARTIST.mp3'),
         mock.call('SECOND_FILE.flac', 'ANY_ARTIST.flac')
     ],
                                       any_order=True)
Ejemplo n.º 4
0
 def test_creates_directory_if_non_existent(self):
     self.mock_path_exists.side_effect = lambda x: (not x ==
                                                    'ANY_FOLDER/ANY_ARTIST'
                                                    '.mp3')
     cli.rename(['ANY_FILE.mp3'], {
         '--dry': False,
         '--pattern': 'ANY_FOLDER/<artist>'
     })
     self.mock_makedirs.assert_called_once_with('ANY_FOLDER', exist_ok=True)
     self.mock_rename.assert_called_once_with('ANY_FILE.mp3',
                                              'ANY_FOLDER/ANY_ARTIST.mp3')
Ejemplo n.º 5
0
    def test_does_not_move_to_existing_file(self):
        self.mock_path_exists.return_value = True
        with logbook.TestHandler() as log_handler:
            cli.rename(['ANY_FILE.mp3'], {
                '--dry': False,
                '--pattern': '<artist>'
            })
            should_log = ("Not moving ANY_FILE.mp3 -> ANY_ARTIST.mp3,"
                          " target file exists!")
            self.assertIn(should_log, log_handler.formatted_records[0])

        self.mock_rename.assert_not_called()
Ejemplo n.º 6
0
 def test_rename_expands_username(self):
     self.mock_path_exists.return_value = False
     cli.rename(['ANY_FILE.mp3'], {'--dry': False, '--pattern': '<artist>'})
     print(self.mock_expanduser.mock_calls)
     self.mock_expanduser.assert_called_once_with('ANY_ARTIST')
Ejemplo n.º 7
0
 def test_fails_if_pattern_has_extension(self):
     with self.assertRaises(cli.UsiqError):
         cli.rename(['ANY_FILE.mp3'], {
             '--dry': False,
             '--pattern': '<artist>.mp3'
         })
Ejemplo n.º 8
0
 def test_honors_dry_run(self):
     cli.rename(['ANY_FILE.mp3'], {'--dry': True, '--pattern': '<artist>'})
     self.mock_rename.assert_not_called()
Ejemplo n.º 9
0
 def test_fails_for_constant_patterns(self):
     with self.assertRaises(cli.UsiqError):
         cli.rename(['ANY_FILE.mp3'], {
             '--dry': False,
             '--pattern': 'CONSTANT_PATTERN'
         })
Ejemplo n.º 10
0
 def test_fails_for_empty_patterns(self):
     with self.assertRaises(cli.UsiqError):
         cli.rename(['ANY_FILE.mp3'], {'--dry': False, '--pattern': ''})