# Path: msaf/exceptions.py
# class NoEstimationsError(MSAFError):
#     '''Exception class for missing estimations'''
#     pass
# 
# class NoReferencesError(MSAFError):
#     '''Exception class for trying evaluations without references'''
#     pass
# 
# 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)


from nose.tools import raises
from types import ModuleType
from msaf.exceptions import NoEstimationsError, NoReferencesError
from msaf.input_output import FileStruct
import numpy.testing as npt
import numpy as np
import os
import pandas as pd
import shutil
import msaf
import msaf.eval as E
           config)

    # Correct Flat
    config["feature"] = "pcp"
    yield (__compute_gt_results, est_file, ref_file, "sf", None, config)
    # Correct Hierarchical
    config["hier"] = True
    yield (__compute_gt_results_hier, est_file, ref_file, "olda", None,
           config)


def test_process_track():
    @raises(AssertionError)
    def __process_track_wrong_names(file_struct):
        E.process_track(file_struct, None, None, None)

    @raises(NoReferencesError)
    def __process_track_no_refs(file_struct):
        E.process_track(file_struct, None, None, None)

    def __process_track_correct(file_struct, bounds_id, labels_id, config):
        res = E.process_track(file_struct, bounds_id, labels_id, config)
        assert "HitRate_3F" in res.keys()

    # Wrong match
    no_match_fs = FileStruct("udontexist.mp3")
    no_match_fs.ref_file = "idontexist.mp3"
    yield (__process_track_wrong_names, no_match_fs)

    # No References

# Path: msaf/exceptions.py
# class NoEstimationsError(MSAFError):
#     '''Exception class for missing estimations'''
#     pass
# 
# class NoReferencesError(MSAFError):
#     '''Exception class for trying evaluations without references'''
#     pass
# 
# 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_eval.py
from nose.tools import raises
from types import ModuleType
from msaf.exceptions import NoEstimationsError, NoReferencesError
from msaf.input_output import FileStruct
import numpy.testing as npt
import numpy as np
import os
import pandas as pd
import shutil
import msaf
import msaf.eval as E

           config)

    # Correct Flat
    config["feature"] = "pcp"
    yield (__compute_gt_results, est_file, ref_file, "sf", None, config)
    # Correct Hierarchical
    config["hier"] = True
    yield (__compute_gt_results_hier, est_file, ref_file, "olda", None,
           config)


def test_process_track():
    @raises(AssertionError)
    def __process_track_wrong_names(file_struct):
        E.process_track(file_struct, None, None, None)

    @raises(NoReferencesError)
    def __process_track_no_refs(file_struct):
        E.process_track(file_struct, None, None, None)

    def __process_track_correct(file_struct, bounds_id, labels_id, config):
        res = E.process_track(file_struct, bounds_id, labels_id, config)
        assert "HitRate_3F" in res.keys()

    # Wrong match
    no_match_fs = FileStruct("udontexist.mp3")
    no_match_fs.ref_file = "idontexist.mp3"
    yield (__process_track_wrong_names, no_match_fs)

    # No References

    no_ref_fs = FileStruct("udontexist.mp3")