Exemplo n.º 1
0
    def test_conditional_include(self):
        testfile = FortranFile(filename="preprocessor.f90",
                               readfile=True,
                               macros=["FOO"])
        assert testfile.uses == ['foo']

        testfile2 = FortranFile(filename="preprocessor.f90", readfile=True)
        assert sorted(testfile2.uses) == sorted(['bar', 'rawr'])
Exemplo n.º 2
0
    def test_include_file(self):
        testfile = FortranFile(filename="preprocessor_include_file.F90",
                               readfile=True,
                               macros=["CAT"],
                               cpp_includes="some_include_dir")
        assert testfile.uses == ['cat']

        testfile2 = FortranFile(filename="preprocessor_include_file.F90",
                                readfile=True)
        assert sorted(testfile2.uses) == sorted(['dog', 'goat'])
Exemplo n.º 3
0
    def test_no_preprocessor(self):
        testfile = FortranFile(filename="preprocessor.f90",
                               readfile=True,
                               macros=["FOO"],
                               use_preprocessor=False)
        assert sorted(testfile.uses) == sorted(['bar', 'foo', 'rawr'])

        testfile2 = FortranFile(filename="preprocessor.f90",
                                readfile=True,
                                use_preprocessor=False)
        assert sorted(testfile2.uses) == sorted(['bar', 'foo', 'rawr'])
Exemplo n.º 4
0
    def test_get_single_module(self):
        testfile = FortranFile(filename="moduleA.f90", readfile=True)
        expected = {"modA": "FortranModule(module, 'moda', 'moduleA.f90')"}

        for key, value in expected.items():
            assert key in testfile.modules
            assert repr(testfile.modules[key]) == value
Exemplo n.º 5
0
 def test_macro_replacement_dict(self):
     testfile = FortranFile(filename="moduleC.f90",
                            readfile=True,
                            macros={
                                "modA": "module_A",
                                "modB": "module_B"
                            })
     assert sorted(testfile.uses) == sorted(["module_A", "module_B"])
Exemplo n.º 6
0
    def test_get_program_and_multiple_modules(self):
        testfile = FortranFile(filename="multiple_modules.f90", readfile=True)
        expected = {
            "modA": "FortranModule(module, 'moda', 'multiple_modules.f90')",
            "modB": "FortranModule(module, 'modb', 'multiple_modules.f90')",
            "modC": "FortranModule(module, 'modc', 'multiple_modules.f90')",
            "progA": "FortranModule(program, 'proga', 'multiple_modules.f90')"
        }

        for key, value in expected.items():
            assert key in testfile.modules
            assert repr(testfile.modules[key]) == value
Exemplo n.º 7
0
    def test_get_use_of_module_with_double_colons(self):
        file_contents = ["module name", "use::module1", "end module"]
        start = 1
        end = len(file_contents)
        source_file = FortranFile(filename='empty', readfile=False)

        module = FortranModule(unit_type='module',
                               name='name',
                               source_file=source_file,
                               text=(file_contents, start, end),
                               macros=None)

        assert module.uses == ['module1']
Exemplo n.º 8
0
    def test_macro_replacement(self):
        file_contents = ["module name", "use foo", "end module"]
        start = 1
        end = len(file_contents)
        source_file = FortranFile(filename='empty', readfile=False)

        module = FortranModule(unit_type='module',
                               name='name',
                               source_file=source_file,
                               text=(file_contents, start, end),
                               macros={'foo': 'module1'})

        assert module.uses == ['module1']
Exemplo n.º 9
0
    def test_get_use_of_repeated_modules(self):
        file_contents = [
            "module name", "use module1", "use module2", "use module3",
            "use module1", "end module"
        ]
        start = 1
        end = len(file_contents)
        source_file = FortranFile(filename='empty', readfile=False)

        module = FortranModule(unit_type='module',
                               name='name',
                               source_file=source_file,
                               text=(file_contents, start, end),
                               macros=None)

        assert set(module.uses) == set(['module1', 'module2', 'module3'])
Exemplo n.º 10
0
    def test_ignore_uses_outside_module(self):
        file_contents = [
            "module module1", "use module2", "end module", "module module2",
            "use module1", "end module"
        ]
        start = 1
        end = 3
        source_file = FortranFile(filename='empty', readfile=False)

        module = FortranModule(unit_type='module',
                               name='name',
                               source_file=source_file,
                               text=(file_contents, start, end),
                               macros=None)

        assert module.uses == ['module2']
Exemplo n.º 11
0
    def test_ignore_variables_named_useX(self):
        file_contents = [
            "module name", "useVariable1 = 1", "use_Variable1 = 1",
            "foo = useVariable2", "foo = use_Variable2", "useFunction1()",
            "use_Function()", "call useSubroutine", "call use_Subroutine",
            "end module"
        ]
        start = 1
        end = len(file_contents)
        source_file = FortranFile(filename='empty', readfile=False)

        module = FortranModule(unit_type='module',
                               name='name',
                               source_file=source_file,
                               text=(file_contents, start, end),
                               macros=None)

        assert module.uses == []
Exemplo n.º 12
0
 def test_empty_uses(self):
     testfile = FortranFile(filename="moduleA.f90", readfile=True)
     assert testfile.uses == []
Exemplo n.º 13
0
 def test_empty(self):
     empty = FortranFile(filename='empty', readfile=False)
     assert empty.filename == "empty"
     assert empty.uses is None
     assert empty.modules is None
     assert empty.depends_on is None
Exemplo n.º 14
0
 def test_single_uses(self):
     testfile = FortranFile(filename="moduleB.f90", readfile=True)
     assert testfile.uses == ['modA']
Exemplo n.º 15
0
 def test_multiple_uses(self):
     testfile = FortranFile(filename="moduleC.f90", readfile=True)
     assert set(testfile.uses) == set(['modA', 'modB'])
Exemplo n.º 16
0
 def test_multiple_uses_in_multiple_units(self):
     testfile = FortranFile(filename="multiple_modules.f90", readfile=True)
     assert set(testfile.uses) == set(
         ['modA', 'modB', 'modC', 'iso_c_binding'])
Exemplo n.º 17
0
 def setup_class(cls):
     cls.testfile = FortranFile(filename="file.f90", readfile=False)
Exemplo n.º 18
0
 def test_macro_replacement_single_value(self):
     testfile = FortranFile(filename="moduleC.f90",
                            readfile=True,
                            macros="modA=module_A")
     assert sorted(testfile.uses) == sorted(["module_A", "modB"])