Ejemplo n.º 1
0
def test_run_script():
    paths = build_directory_structure()

    # create config
    config = ConfigCmd(RERANK_DIR + '/conf/config.xml', RERANK_DIR)

    # initialize rerankCmd
    rerank = RerankCmd()

    script = Path('../../../../../librec_auto/core/cmd/rerank/far_rerank.py')

    param_spec = ['--max_len=4', '--lambda=0.3', '--binary=False']

    rerank._files = config.get_files()

    rerank._files.create_exp_paths(0)  # create experiment tuple

    sub_paths = rerank._files.get_exp_paths(0)

    rerank._config = config  # set config

    result = rerank.run_script(script=script,
                               sub_paths=sub_paths,
                               original_path=paths['original_path'],
                               param_spec=param_spec)

    assert result == 0  # check that the script ran successfully

    # check the reranked results are correct
    assert filecmp.cmp(RERANK_DATA_DIR / Path('result-out-1.txt'),
                       paths['results_path'] / 'out-1.txt')
    assert filecmp.cmp(RERANK_DATA_DIR / Path('result-out-2.txt'),
                       paths['results_path'] / 'out-2.txt')

    rmtree(RERANK_DIR)  # delete the reranking directory
Ejemplo n.º 2
0
def test_dry_run(capsys):
    captured = capsys.readouterr()  # capture stdout

    build_directory_structure()

    # create config
    config = ConfigCmd(RERANK_DIR + '/conf/config.xml', RERANK_DIR)

    # initialize rerankCmd
    rerank = RerankCmd()

    rerank._files = config.get_files()

    rerank._files.create_exp_paths(0)  # create experiment tuple

    sub_paths = rerank._files.get_exp_paths(0)

    rerank._config = config  # set config

    rerank.dry_run(config)

    rmtree(RERANK_DIR)  # delete the reranking directory

    # check stdout
    out, err = capsys.readouterr()

    # for exp0000 -> only one experiment
    # re-rank script -> wildcard to handle absolute path, far_rerank.py
    # parameters from config.xml

    # use a wildcard for the beginning of the absolute path
    if name == 'nt':
        # running on Windows
        out_pattern = r"librec-auto \(DR\): Running re-ranking command RerankCmd\(\) for exp00000\n\tRe-rank script: (.*)librec-auto\\librec_auto\\core\\cmd\\rerank\\far_rerank\.py\n\tParameters: \['--max_len=4', '--lambda=0\.3', '--binary=False']\n$"
    else:
        # non-Windows
        out_pattern = r"librec-auto \(DR\): Running re-ranking command RerankCmd\(\) for exp00000\n\tRe-rank script: (.*)librec-auto\/librec_auto\/core\/cmd\/rerank\/far_rerank\.py\n\tParameters: \['--max_len=4', '--lambda=0\.3', '--binary=False']\n$"

    # assert that there is a match
    assert re.match(out_pattern, out) != None
Ejemplo n.º 3
0
def _get_config():
    return ConfigCmd('config.xml', '')
Ejemplo n.º 4
0
def _get_config():
    config = ConfigCmd('librec_auto/test/test-config.xml', '')
    config._files.set_post_path(POST_DIR)
    return config
Ejemplo n.º 5
0
def _get_config():
    return ConfigCmd('librec_auto/test/test-config.xml', '')