# 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(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 1

    # Three level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(three_jams)
    assert len(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 3


def test_find_estimation():
    est_file = os.path.join("fixtures", "01-Sargon-Mindless-ests.jams")
    jam = jams.load(est_file)
    params = {"hier": False}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 21


def test_find_estimation_multiple():
    est_file = os.path.join("fixtures", "01-Sargon-Mindless-est-multiple.jams")
    jam = jams.load(est_file)
    params = {"hier": True}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 86


@raises(AssertionError)
def test_save_estimations_hier_wrong():

# 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(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 1

    # Three level file
    hier_bounds, hier_labels, hier_levels = \
        msaf.io.read_hier_references(three_jams)
    assert len(hier_bounds) == len(hier_labels) and \
        len(hier_labels) == len(hier_levels)
    assert len(hier_levels) == 3


def test_find_estimation():
    est_file = os.path.join("fixtures", "01-Sargon-Mindless-ests.jams")
    jam = jams.load(est_file)
    params = {"hier": False}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 21


def test_find_estimation_multiple():
    est_file = os.path.join("fixtures", "01-Sargon-Mindless-est-multiple.jams")
    jam = jams.load(est_file)
    params = {"hier": True}
    ann = msaf.io.find_estimation(jam, "sf", None, params)
    assert len(ann.data) == 86


@raises(AssertionError)
def test_save_estimations_hier_wrong():

    file_struct = FileStruct("dummy")