def test_project_os_roundtrip(): #delete PROJECT_ENV if it's currently set os.environ.pop("PROJECT_ENV", None) env_obs = ProjectEnv.detect_from_os() assert env_obs == None env_obs = ProjectEnv.detect_from_os(fallback_to_default=True) assert env_obs == ProjectEnv.default_instance() env1 = ProjectEnv.default_instance() assert not env1 == None env1.write_to_os() env_obs = ProjectEnv.detect_from_os() assert env1 == env_obs env_obs = ProjectEnv.detect_from_os(fallback_to_default=True) assert env1 == env_obs return
def build_and_test(project_root_dir): """ run all compilation and unit tests """ stage_results = list() log("START ci_ops.BUILD_AND_TEST") py_compile_stage = _perform_stage('python compilation ', compile_ops._compile, project_root_dir, 'python', ProjectEnv.default_instance(), RunLevel.development_instance()) stage_results.append(py_compile_stage) js_compile_stage = _perform_stage('web_assets compilation', compile_ops._compile, project_root_dir, 'web_assets', ProjectEnv.hello_world_instance(), RunLevel.development_instance()) stage_results.append(js_compile_stage) build_containers_stage = _perform_stage('build containers ', docker_ops._docker_action, 'build', 'all', ProjectEnv.hello_world_instance(), RunLevel.development_instance(), NestSite.localhost_instance(), project_root_dir) stage_results.append(build_containers_stage) #run pytests and clienttests against the hello_world_app containers startup_containers_stage = _perform_stage( 'startup containers ', docker_ops._docker_action, 'startup', 'all', ProjectEnv.hello_world_instance(), RunLevel.development_instance(), NestSite.localhost_instance(), project_root_dir) stage_results.append(startup_containers_stage) clienttest_stage = _perform_stage('clienttest ', clienttest_ops._run_unit_test, project_root_dir) stage_results.append(clienttest_stage) pytest_stage = _perform_stage('pytest tests/unit/ ', pytest_ops._run_unit_test, project_root_dir, True) stage_results.append(pytest_stage) teardown_containers_stage = _perform_stage( 'teardown containers ', docker_ops._docker_action, 'teardown', 'all', ProjectEnv.hello_world_instance(), RunLevel.development_instance(), NestSite.localhost_instance(), project_root_dir) stage_results.append(teardown_containers_stage) #test the lifecycle and smoke scripts of all projects project_names = nest_envs.VALID_PROJECT_NAMES for project_name in project_names: project_env = ProjectEnv(project_name) project_stage_results = _perform_project_stages( project_env, project_root_dir) stage_results += project_stage_results exit_code = _finalize_build(stage_results) log("BUILD_AND_TESTS returning exit_code: " + str(exit_code)) return exit_code