Exemple #1
0
def test_get_filename():
    """ Tests genreml.model.utils.file_handling.get_filename function """
    # Nominal operation
    pid = os.getpid()
    base_path = './test_dir_parent'
    sub_path = '/audio-clips{0}/'.format(str(pid))
    file_name = 'some_file.txt'
    full_path = file_handling.get_directory_path(sub_path + file_name,
                                                 base_path)
    parent_dir_path = file_handling.get_directory_path(sub_path, base_path)
    assert file_handling.get_filename(full_path) == file_name
    # Bad input
    with pytest.raises(ValueError):
        file_handling.get_filename(parent_dir_path)
Exemple #2
0
 def extract(self,
             song_name=None,
             artist=None,
             file_path=None,
             yt_url=None):
     """ Extracts data for the given song name and artist using the active downloader
     :param string song_name: the name of the song to download
     :param string artist: the name of the song's artist
     :param file_path: an optional path to save the song file to (must be an absolute path including the song file)
     :param yt_url: an optional param to extract song data directly from YouTube url
     """
     # If no full path given, construct one from config
     if not file_path:
         file_path = self.config.DESTINATION_FILEPATH
         full_path = file_handling.get_directory_path(file_path)
         file_handling.create_directory(full_path)
         file_name = '{0}_{1}_clip.{2}'.format(song_name, artist,
                                               AudioConfig.AUDIO_FORMAT)
         file_path = "{0}{1}".format(full_path, file_name)
     logging.info("Changing working directory to {0}".format(file_path))
     file_handling.change_directory_to(file_path)
     if yt_url:
         self.downloader.download(file_path, url=yt_url)
     else:
         search_query = '{0}+{1}'.format(song_name, artist)
         self.downloader.download(file_path, search_values=[search_query])
Exemple #3
0
def test_get_directory_path():
    """ Tests genreml.model.utils.file_handling.get_directory_path function """
    # Nominal operation
    base_path = '/Users/JaneDoe/Documents'
    sub_path = '/audio-clips/'
    assert file_handling.get_directory_path(
        sub_path, base_path) == '/Users/JaneDoe/Documents/audio-clips/'
Exemple #4
0
def test_get_parent_directory():
    """ Tests genreml.model.utils.file_handling.get_parent_directory function """
    # Nominal operation
    pid = os.getpid()
    base_path = './test_dir_parent'
    sub_path = '/audio-clips{0}/'.format(str(pid))
    file_name = 'some_file.txt'
    full_path = file_handling.get_directory_path(sub_path + file_name,
                                                 base_path)
    parent_dir_path = file_handling.get_directory_path(sub_path, base_path)
    expected_result = sub_path.split('/')[1]
    file_handling.create_directory(full_path)
    assert file_handling.get_parent_directory(full_path).split(
        '/')[-1] == expected_result
    assert file_handling.get_parent_directory(parent_dir_path).split(
        '/')[-1] == expected_result