def test_parser_parse_linelength(): '''Check that the parse() method in the Parser() class raises an exception if one or more of the lines is too long (>132 characters) in the supplied input file when _line_length is set to True and does not raise an exception by default. ''' parser = Parser() parser.parse(os.path.join(LFRIC_TEST_PATH, "13_alg_long_line.f90")) parser = Parser(line_length=True) with pytest.raises(ParseError) as info: parser.parse(os.path.join(LFRIC_TEST_PATH, "13_alg_long_line.f90")) assert ("the file does not conform to the specified 132 line length " "limit" in str(info.value))
def test_parser_parse_nemo(): '''Check that the parse() method in the Parser() class returns the expected results (None, and an fparser2 ast) when using the NEMO API. We actually use an LFRic algorithm file here but it does not matter as we are only parsing the code. ''' parser = Parser(api="nemo") res1, res2 = parser.parse(os.path.join( LFRIC_TEST_PATH, "1_single_invoke.f90")) assert res1 is None assert isinstance(res2, Program) assert "PROGRAM single_invoke" in str(res2)
def test_parser_parse(tmpdir): '''Test that if no relevant code is found in the algorithm file then the appropriate exception is raised. ''' tmp = Parser() filename = str(tmpdir.join("empty.f90")) ffile = open(filename, "w") ffile.write("") ffile.close() with pytest.raises(ParseError) as excinfo: _ = tmp.parse(filename) assert ("Program, module, function or subroutine not found in parse tree " "for file") in str(excinfo.value)
def test_parser_parse(): '''Check that the parse() method in the Parser() class returns the expected results (fparser2 ast and a FileInfo instance) when using an API other than the NEMO API. Also test that the filename is stored in _alg_filename. ''' parser = Parser(api="dynamo0.3") assert parser._alg_filename is None res1, res2 = parser.parse(os.path.join( LFRIC_TEST_PATH, "1_single_invoke.f90")) assert "1_single_invoke.f90" in parser._alg_filename assert isinstance(res1, Program) assert "PROGRAM single_invoke" in str(res1) assert isinstance(res2, FileInfo) assert res2.name == "single_invoke"