def test_main_stop_after_uncrecognized(abc_instance_file): """Test that --stop_after raises an error on unknown.""" app.FLAGS.unparse_flags() app.FLAGS( ['argv[0]', '--config', abc_instance_file, '--stop_after', 'foo']) with pytest.raises(app.UsageError): clgen.main([])
def test_main_print_cache_invalid_argument(abc_instance_file): """Test that UsageError raised if --print_cache_path arg not valid.""" app.FLAGS.unparse_flags() app.FLAGS( ['argv[0]', '--config', abc_instance_file, '--print_cache_path=foo']) with pytest.raises(app.UsageError) as e_info: clgen.main([]) assert "Invalid --print_cache_path argument: 'foo'" == str(e_info.value)
def test_main_stop_after_train(abc_instance_file): """Test that --stop_after train trains the model.""" app.FLAGS.unparse_flags() app.FLAGS( ['argv[0]', '--config', abc_instance_file, '--stop_after', 'train']) clgen.main([]) instance = clgen.Instance( pbutil.FromFile(pathlib.Path(abc_instance_file), clgen_pb2.Instance())) assert instance.model.is_trained
def test_main_stop_after_corpus(abc_instance_file): """Test that --stop_after corpus prevents model training.""" app.FLAGS.unparse_flags() app.FLAGS( ['argv[0]', '--config', abc_instance_file, '--stop_after', 'corpus']) clgen.main([]) instance = clgen.Instance( pbutil.FromFile(pathlib.Path(abc_instance_file), clgen_pb2.Instance())) assert not instance.model.is_trained
def test_main_print_cache_path_model(abc_instance_file, capsys): """Test that --print_cache_path=model prints directory path.""" app.FLAGS.unparse_flags() app.FLAGS( ['argv[0]', '--config', abc_instance_file, '--print_cache_path=model']) clgen.main([]) out, err = capsys.readouterr() assert '/model/' in out assert pathlib.Path(out.strip()).is_dir()
def test_main_config_file_not_found(): """Test that UsageError is raised if --config flag not found.""" with tempfile.TemporaryDirectory() as d: app.FLAGS.unparse_flags() app.FLAGS(['argv[0]', '--config', f'{d}/config.pbtxt']) with pytest.raises(app.UsageError) as e_info: clgen.main(['argv[0]']) assert f"CLgen --config file not found: '{d}/config.pbtxt'" == str( e_info.value)
def test_main_print_cache_path_sampler(abc_instance_file, capsys): """Test that --print_cache_path=sampler prints directory path.""" app.FLAGS.unparse_flags() app.FLAGS([ 'argv[0]', '--config', abc_instance_file, '--print_cache_path=sampler' ]) clgen.main([]) out, err = capsys.readouterr() assert '/samples/' in out # A sampler's cache isn't created until Sample() is called. assert not pathlib.Path(out.strip()).is_dir()
def Main(): """Main entry point.""" app.FLAGS(['argv[0]', '--vmodule=*=5']) # Get the file path of the calling function. This is used to identify the # script to run the tests of. frame = inspect.stack()[1] module = inspect.getmodule(frame[0]) file_path = module.__file__ app.RunWithArgs(lambda argv: RunPytestOnFileAndExit(file_path, argv))
def test_main_min_samples(abc_instance_file): """Test that min_samples samples are produced.""" app.FLAGS.unparse_flags() app.FLAGS(['argv[0]', '--config', abc_instance_file, '--min_samples', '1']) clgen.main([])
def test_RunWithErrorHandling_exception_debug(clgen_cache_dir): """Test that FLAGS.debug disables exception catching.""" del clgen_cache_dir app.FLAGS(['argv[0]', '--clgen_debug']) with pytest.raises(ZeroDivisionError): clgen.RunWithErrorHandling(lambda a, b: a // b, 1, 0)