def test_add_filter_config_var(): """Tests adding a var that already exists.""" configparam = EnumStr(".wav", ".mp3", ".aif", convert=lambda x: x.replace("wav", "aif")) AddConfigVar('new_var', "doc", configparam) assert msaf.config.new_var == ".aif"
"""Default configuration parameters for MSAF.""" import logging import numpy as np from msaf.configparser import \ (AddConfigVar, BoolParam, ConfigParam, EnumStr, FloatParam, IntParam, StrParam, ListParam, MsafConfigParser) _logger = logging.getLogger('msaf.configdefaults') config = MsafConfigParser() # Globals AddConfigVar('default_bound_id', "Default boundary detection algorithm", EnumStr("sf", "cnmf", "foote", "olda", "scluster", "gt")) AddConfigVar('default_label_id', "Default label detection algorithm", EnumStr(None, "cnmf", "fmc2d", "scluster")) # Global analysis parameters AddConfigVar('sample_rate', "Default Sample Rate to be used.", IntParam(22050)) AddConfigVar('n_fft', "FFT size", IntParam(4096)) AddConfigVar('hop_size', "Hop length in samples", IntParam(1024)) # Files and dirs AddConfigVar('results_dir', "Default directory to store results.", StrParam("results")) AddConfigVar('results_ext', "Default extension for the results file.", StrParam(".csv")) AddConfigVar('out_boundaries_ext', "Default extension for output audio " "bounds.", StrParam("-bounds.wav")) AddConfigVar('minimum_frames', "Minimum number of frames to activate "
def test_wrong_addconfig_root_multsections(): """Tests adding a var that already exists in the root with multiple sections and wrong root.""" conf = namedtuple('conf', ['cqt']) AddConfigVar('cqt.bins', "doc", IntParam(1), root=conf)
def test_wrong_addconfig_root(): """Tests adding a var that already exists in the root.""" AddConfigVar('sample_rate', "doc", IntParam(1), root=msaf.config)
def test_none_str(): """Adds a None String variable.""" AddConfigVar('test.my_none_str', "Test None string", StrParam(None)) assert msaf.config.test.my_none_str is None
def test_bool_var(): """Adds a boolean variable.""" AddConfigVar('test.my_new_bool', "Test bool variable only for testing", BoolParam(True)) assert msaf.config.test.my_new_bool
def test_wrong_list_param(): """Tests a wrong list param.""" AddConfigVar('new_var7', "doc", ListParam(42))
def test_add_var(): """Adds a config variable and checks that it's correctly stored.""" val = 10 AddConfigVar('test.new_var', "Test Variable only for unit testing", IntParam(val)) assert msaf.config.test.new_var == val
def test_empty_list_param(): """Tests an empty list param.""" AddConfigVar('new_var6', "doc", ListParam([]))
def test_wrong_boolparam(): """Tests a wrong boolean param.""" AddConfigVar('new_var5', "doc", BoolParam("falsitto"))
def test_false_boolparam(): """Tests a false boolean param.""" AddConfigVar('new_var4', "doc", BoolParam("false")) assert not msaf.config.new_var4
def test_invalid_enumstr(): """Tests invalid enumstrings.""" AddConfigVar('new_var4', "doc", EnumStr("caca", 42, "merda"))
def test_allowoverride(): """Tests overriding a variable that can be overridden.""" configparam = EnumStr("caca", "merda", allow_override=True) AddConfigVar('new_var3', "doc", configparam) msaf.config.new_var3 = "merda" assert msaf.config.new_var3 == "merda"
def test_allowoverride_fail(): """Tests overriding a variable that can't be overridden.""" configparam = EnumStr("caca", "merda", allow_override=False) AddConfigVar('new_var2', "doc", configparam) msaf.config.new_var2 = "caca2" # Raise Exception
def test_wrong_callable_arg(): """Tests adding a var with a wrong callable default param.""" # We can add it AddConfigVar('my_int', "doc", IntParam(sorted)) # but it should fail when retrieving it msaf.config.my_int
def test_add_existing_config_var(): """Tests adding a var that already exists.""" AddConfigVar('sample_rate', "doc", IntParam(1))