# Path: msaf/input_output.py
# class FileStruct:
#     def __init__(self, audio_file):
#         """Creates the entire file structure given the audio file."""
#         self.ds_path = os.path.dirname(os.path.dirname(audio_file))
#         self.audio_file = audio_file
#         self.est_file = self._get_dataset_file(ds_config.estimations_dir,
#                                                ds_config.estimations_ext)
#         self.features_file = self._get_dataset_file(ds_config.features_dir,
#                                                     ds_config.features_ext)
#         self.ref_file = self._get_dataset_file(ds_config.references_dir,
#                                                ds_config.references_ext)
# 
#     def _get_dataset_file(self, dir, ext):
#         """Gets the desired dataset file."""
#         audio_file_ext = "." + self.audio_file.split(".")[-1]
#         base_file = os.path.basename(self.audio_file).replace(
#             audio_file_ext, ext)
#         return os.path.join(self.ds_path, dir, base_file)
# 
#     def __repr__(self):
#         """Prints the file structure."""
#         return "FileStruct(\n\tds_path=%s,\n\taudio_file=%s,\n\test_file=%s," \
#             "\n\tfeatures_file=%s,\n\tref_file=%s\n)" % (
#                 self.ds_path, self.audio_file, self.est_file,
#                 self.features_file, self.ref_file)


import jams
import librosa
import numpy as np
import os
import shutil
import msaf
from nose.tools import raises
from msaf.input_output import FileStruct
    assert len(ann.data) == 86


@raises(AssertionError)
def test_save_estimations_hier_wrong():
    file_struct = FileStruct("dummy")
    file_struct.features_file = os.path.join("fixtures",
                                             "01_-_Come_Together.json")

    # Wrong times and labels (don't match)
    times = [np.arange(0, 10, 2), np.arange(0, 10, 1)]
    labels = [['A', 'B'], ['a', 'a', 'b']]

    # Should raise assertion error
    msaf.io.save_estimations(file_struct, times, labels, None, None)


def test_save_estimations_existing():
    # Copy estimations file temporarily
    est_file = "tmp.jams"
    shutil.copy(os.path.join("fixtures", "01-Sargon-Mindless-ests.jams"),
                est_file)

    # First, find estimation
    jam = jams.load(est_file)
    params = {"hier": False}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 21

    # Add to estimation which will replace it

# Path: msaf/input_output.py
# class FileStruct:
#     def __init__(self, audio_file):
#         """Creates the entire file structure given the audio file."""
#         self.ds_path = os.path.dirname(os.path.dirname(audio_file))
#         self.audio_file = audio_file
#         self.est_file = self._get_dataset_file(ds_config.estimations_dir,
#                                                ds_config.estimations_ext)
#         self.features_file = self._get_dataset_file(ds_config.features_dir,
#                                                     ds_config.features_ext)
#         self.ref_file = self._get_dataset_file(ds_config.references_dir,
#                                                ds_config.references_ext)
# 
#     def _get_dataset_file(self, dir, ext):
#         """Gets the desired dataset file."""
#         audio_file_ext = "." + self.audio_file.split(".")[-1]
#         base_file = os.path.basename(self.audio_file).replace(
#             audio_file_ext, ext)
#         return os.path.join(self.ds_path, dir, base_file)
# 
#     def __repr__(self):
#         """Prints the file structure."""
#         return "FileStruct(\n\tds_path=%s,\n\taudio_file=%s,\n\test_file=%s," \
#             "\n\tfeatures_file=%s,\n\tref_file=%s\n)" % (
#                 self.ds_path, self.audio_file, self.est_file,
#                 self.features_file, self.ref_file)


# Path: tests/test_input_output.py
import jams
import librosa
import numpy as np
import os
import shutil
import msaf
from nose.tools import raises
from msaf.input_output import FileStruct

    assert len(ann.data) == 86


@raises(AssertionError)
def test_save_estimations_hier_wrong():
    file_struct = FileStruct("dummy")
    file_struct.features_file = os.path.join("fixtures",
                                             "01_-_Come_Together.json")

    # Wrong times and labels (don't match)
    times = [np.arange(0, 10, 2), np.arange(0, 10, 1)]
    labels = [['A', 'B'], ['a', 'a', 'b']]

    # Should raise assertion error
    msaf.io.save_estimations(file_struct, times, labels, None, None)


def test_save_estimations_existing():
    # Copy estimations file temporarily
    est_file = "tmp.jams"
    shutil.copy(os.path.join("fixtures", "01-Sargon-Mindless-ests.jams"),
                est_file)

    # First, find estimation
    jam = jams.load(est_file)
    params = {"hier": False}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 21

    # Add to estimation which will replace it

    file_struct = FileStruct("dummy")