def test_does_not_contain_correct_def(self): """Test file_contains_python_function without the correct def""" contents = """ def bar(): def notfoo(): def baz(): """ filepath = self.create_test_file(contents) self.assertFalse(file_contains_python_function(filepath, "foo"))
def test_contains_correct_def_and_others(self): """Test file_contains_python_function with a correct def mixed with other defs""" contents = """ def bar(): def foo(): def baz(): """ filepath = self.create_test_file(contents) self.assertTrue(file_contains_python_function(filepath, "foo"))
components use multiple user_nl files. These components can define a function in cime_config/buildnml named get_user_nl_list, which returns a list of user_nl files that need to be staged in the case directory. For example, in a run where CISM is modeling both Antarctica and Greenland, its get_user_nl_list function will return ['user_nl_cism', 'user_nl_cism_ais', 'user_nl_cism_gris']. If that function is NOT defined in the component's buildnml, then we return the given default_nlfile. """ # Check if buildnml is present in the expected location, and if so, whether it # contains the function "get_user_nl_list"; if so, we'll import the module and call # that function; if not, we'll fall back on the default value. buildnml_path = os.path.join(model_dir, "buildnml") has_function = False if os.path.isfile(buildnml_path) and file_contains_python_function( buildnml_path, "get_user_nl_list"): has_function = True if has_function: comp_buildnml = import_from_file("comp_buildnml", buildnml_path) return comp_buildnml.get_user_nl_list(case) else: return [default_nlfile] ############################################################################### def _create_macros_cmake(caseroot, cmake_macros_dir, mach_obj, compiler, case_cmake_path): ############################################################################### if not os.path.isfile(os.path.join(caseroot, "Macros.cmake")): safe_copy(os.path.join(cmake_macros_dir, "Macros.cmake"), caseroot)