def test_guess_test():
    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname, nb_times=10)

        report = guesser.Guess().test(dirname)
        assert 0 <= report['overall-accuracy'] <= 1
        assert report['per-language']['C']['nb-files'] == 10
        assert report['per-language']['Python']['nb-files'] == 10
Ejemplo n.º 2
0
def test_extract_from_files():
    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname, nb_times=10)

        files = utils.search_files(dirname, EXTENSIONS)
        arrays = utils.extract_from_files(files, LANGUAGES)

        assert len(arrays) == 2
        assert all(len(values) == 20 for values in arrays)
Ejemplo n.º 3
0
def test_search_files():
    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname)

        # Not enough files in the directory
        with pytest.raises(GuesslangError):
            utils.search_files(dirname, EXTENSIONS)

    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname, nb_times=10)

        files = utils.search_files(dirname, EXTENSIONS)
        assert len(files) == 20
def test_guess_learn():
    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname, nb_times=10)

        # Cannot learn using default model
        with pytest.raises(GuesslangError):
            guesser.Guess().learn(dirname)

    temp_model_dir = tempfile.TemporaryDirectory()
    with tempfile.TemporaryDirectory() as dirname:
        copy_fixtures(dirname, nb_times=10)

        accuracy = guesser.Guess(temp_model_dir.name).learn(dirname)
        assert 0 <= accuracy <= 1

    try:
        temp_model_dir.cleanup()
    except OSError:
        # Occures on Windows only
        # - OSError: [WinError 145] The directory is not empty
        pass