コード例 #1
0
    def test_write_depends_skip_programs(self, datadir):
        expected_contents = [
            DEPFILE_HEADER,
            "moduleA.o :",
            "moduleB.o : moduleA.o",
            "moduleC.o : moduleA.o moduleB.o",
            "moduleD.o : moduleC.o",
            "moduleE.o :",
            "multiple_modules.o :",
            "programTest.o : moduleC.o moduleD.o",
        ]

        testproject = FortranProject()
        testproject.write_depends(skip_programs=True)

        with open(str(datadir.join("makefile.dep")), 'r') as f:
            contents = f.read()

        # A little manipulation to remove extraneous whitespace is
        # required in order for a clean comparison
        contents = contents.replace('\\\n\t', ' ')
        contents = re.sub(r' +', ' ', contents)
        contents = [
            line.lstrip().rstrip(" \t\n") for line in contents.splitlines()
            if line != ''
        ]

        assert sorted(expected_contents) == sorted(contents)
コード例 #2
0
    def test_write_depends_no_overwrite(self, datadir):
        expected_contents = [
            DEPFILE_HEADER,
            "moduleA.o :",
            "moduleB.o : moduleA.o",
            "moduleC.o : moduleA.o moduleB.o",
            "moduleD.o : moduleC.o",
            "moduleE.o :",
            "multiple_modules.o :",
            "programTest.o : moduleC.o moduleD.o",
            "progA : multiple_modules.o",
            "test : moduleA.o moduleB.o moduleC.o moduleD.o programTest.o",
        ]

        FortranProject().write_depends()
        testproject = FortranProject(exclude_files="multiple_modules.f90")

        with mock.patch.object(builtins, 'input', lambda x: 'N'):
            testproject.write_depends(overwrite=False)

        with open(str(datadir.join("makefile.dep")), 'r') as f:
            contents = f.read()

        # A little manipulation to remove extraneous whitespace is
        # required in order for a clean comparison
        contents = contents.replace('\\\n\t', ' ')
        contents = re.sub(r' +', ' ', contents)
        contents = [
            line.lstrip().rstrip(" \t\n") for line in contents.splitlines()
            if line != ''
        ]

        assert sorted(expected_contents) == sorted(contents)
コード例 #3
0
    def test_write_depends_no_overwrite(self, datadir):
        expected_contents = [
            DEPFILE_HEADER,
            "moduleA.o :",
            "moduleB.o : moduleA.o",
            "moduleC.o : moduleA.o moduleB.o",
            "moduleD.o : moduleC.o",
            "moduleE.o :",
            "multiple_modules.o :",
            "programTest.o : moduleC.o moduleD.o",
            "progA : multiple_modules.o",
            "test : moduleA.o moduleB.o moduleC.o moduleD.o programTest.o",
        ]

        FortranProject().write_depends()
        testproject = FortranProject(exclude_files="multiple_modules.f90")

        with mock.patch.object(builtins, 'input', lambda x: 'N'):
            testproject.write_depends(overwrite=False)

        with open(str(datadir.join("makefile.dep")), 'r') as f:
            contents = f.read()

        # A little manipulation to remove extraneous whitespace is
        # required in order for a clean comparison
        contents = contents.replace('\\\n\t', ' ')
        contents = re.sub(r' +', ' ', contents)
        contents = [line.lstrip().rstrip(" \t\n") for line in contents.splitlines() if line != '']

        assert sorted(expected_contents) == sorted(contents)
コード例 #4
0
    def test_write_depends_skip_programs(self, datadir):
        expected_contents = [
            DEPFILE_HEADER,
            "moduleA.o :",
            "moduleB.o : moduleA.o",
            "moduleC.o : moduleA.o moduleB.o",
            "moduleD.o : moduleC.o",
            "moduleE.o :",
            "multiple_modules.o :",
            "programTest.o : moduleC.o moduleD.o",
        ]

        testproject = FortranProject()
        testproject.write_depends(skip_programs=True)

        with open(str(datadir.join("makefile.dep")), 'r') as f:
            contents = f.read()

        # A little manipulation to remove extraneous whitespace is
        # required in order for a clean comparison
        contents = contents.replace('\\\n\t', ' ')
        contents = re.sub(r' +', ' ', contents)
        contents = [line.lstrip().rstrip(" \t\n") for line in contents.splitlines() if line != '']

        assert sorted(expected_contents) == sorted(contents)
コード例 #5
0
    def test_get_all_used_modules(self):
        expected_used = {
            "progA": sorted(["modF", "modG", "modH"]),
            "test": sorted(["modA", "modB", "modC", "modD"]),
        }

        testproject = FortranProject()
        used_by_program = {}
        for program in testproject.programs.keys():
            used_by_program[program] = testproject.get_all_used_modules(program)

        assert expected_used == used_by_program
コード例 #6
0
    def test_get_all_used_modules(self):
        expected_used = {
            "progA": sorted(["modF", "modG", "modH"]),
            "test": sorted(["modA", "modB", "modC", "modD"]),
        }

        testproject = FortranProject()
        used_by_program = {}
        for program in testproject.programs.keys():
            used_by_program[program] = testproject.get_all_used_modules(
                program)

        assert expected_used == used_by_program
コード例 #7
0
    def test_get_all_programs(self):
        testproject = FortranProject()
        expected_programs = [
            "progA",
            "test",
        ]

        assert sorted(testproject.programs) == sorted(expected_programs)
コード例 #8
0
 def test_ignore_modules(self):
     testproject = FortranProject(files="multiple_modules.f90",
                                  ignore_modules="modF")
     assert sorted(["modG", "modH",
                    "progA"]) == sorted(testproject.modules.keys())
     assert [] == testproject.modules["modG"].uses
     assert (sorted(["modG", "modH"]) == sorted(
         testproject.files["multiple_modules.f90"].uses))
コード例 #9
0
    def test_exclude_files(self):
        testproject = FortranProject(exclude_files="multiple_modules.f90")
        expected_files = [
            "moduleA.f90", "moduleB.f90", "moduleC.f90", "moduleD.f90",
            "moduleE.f90", "programTest.f90"
        ]

        assert sorted(testproject.files) == sorted(expected_files)
コード例 #10
0
    def test_get_all_used_files(self):
        expected_used = {
            "progA": sorted(["multiple_modules.f90"]),
            "test": sorted([
                "moduleA.f90",
                "moduleB.f90",
                "moduleC.f90",
                "moduleD.f90",
                "programTest.f90",
            ]),
        }

        testproject = FortranProject()
        used_by_program = {}
        for program in testproject.programs.keys():
            used_by_program[program] = testproject.get_all_used_files(program)

        assert expected_used == used_by_program
コード例 #11
0
    def test_get_all_used_files(self):
        expected_used = {
            "progA":
            sorted(["multiple_modules.f90"]),
            "test":
            sorted([
                "moduleA.f90",
                "moduleB.f90",
                "moduleC.f90",
                "moduleD.f90",
                "programTest.f90",
            ]),
        }

        testproject = FortranProject()
        used_by_program = {}
        for program in testproject.programs.keys():
            used_by_program[program] = testproject.get_all_used_files(program)

        assert expected_used == used_by_program
コード例 #12
0
ファイル: __main__.py プロジェクト: ZedThree/fort_depend.py
def main(args=None):
    """Run the module as a script

    """

    parser = create_argument_parser()
    # Parse the command line arguments
    args = parser.parse_args()

    # Assemble a dictionary out of the macro definitions
    macros = {}
    if args.D:
        for arg in args.D:
            for var in arg:
                if '=' not in var:
                    macros[var] = ''
                else:
                    temp = var.split('=')
                    macros[temp[0]] = temp[1]

    output = args.output[0] if args.output else None
    build = args.build[0] if args.build else ''

    # Sorts out the terminal colours on Windows
    strip_colours = not args.colour
    colorama.init(strip=strip_colours)

    project = FortranProject(files=args.files, exclude_files=args.exclude_files,
                             ignore_modules=args.ignore_modules,
                             macros=macros, cpp_includes=args.I,
                             verbose=args.verbose,
                             use_preprocessor=not args.no_preprocessor)

    if output is not None:
        project.write_depends(filename=output, overwrite=args.overwrite, build=build,
                              skip_programs=args.skip_programs)

    if args.graph:
        project.make_graph()
コード例 #13
0
    def test_get_all_modules(self):
        testproject = FortranProject()
        expected_modules = [
            "modA",
            "modB",
            "modC",
            "modD",
            "modE",
            "modF",
            "modG",
            "modH",
            "progA",
            "test",
        ]

        assert sorted(testproject.modules) == sorted(expected_modules)
コード例 #14
0
    def test_depends_by_module(self):
        """This one is a little complicated...

        The dictionary depends_by_module uses FortranModule objects as
        keys. To save having to actually construct these, we instead
        need to reconstruct the dictionary with the repr strings as
        keys. Similarly for the values. We can then do comparisons on
        sets of strings.
        """
        testproject = FortranProject(exclude_files="multiple_modules.f90")
        reprs = {
            "modA": "FortranModule(module, 'moda', 'moduleA.f90')",
            "modB": "FortranModule(module, 'modb', 'moduleB.f90')",
            "modC": "FortranModule(module, 'modc', 'moduleC.f90')",
            "modD": "FortranModule(module, 'modd', 'moduleD.f90')",
            "modE": "FortranModule(module, 'mode', 'moduleE.f90')",
            "mpi": "FortranModule(module, 'mpi', 'empty')",
            "test": "FortranModule(program, 'test', 'programTest.f90')",
        }

        expected = {
            reprs["modA"]: [],
            reprs["modB"]: [reprs["modA"]],
            reprs["modC"]: [reprs["modA"], reprs["modB"]],
            reprs["modD"]: [reprs["modC"]],
            reprs["modE"]: [reprs["mpi"]],
            reprs["test"]: [reprs["modC"], reprs["modD"]],
        }

        depends_by_module_repr = {}
        for key, value in testproject.depends_by_module.items():
            depends_by_module_repr[repr(key)] = value

        for key, value in expected.items():
            assert key in depends_by_module_repr
            reprs = sorted([repr(foo) for foo in depends_by_module_repr[key]])
            assert reprs == sorted(value)
コード例 #15
0
ファイル: __main__.py プロジェクト: trmwzm/fort_depend.py
def main(args=None):
    """Run the module as a script

    """

    parser = create_argument_parser()
    # Parse the command line arguments
    args = parser.parse_args()

    # Assemble a dictionary out of the macro definitions
    macros = {}
    if args.D:
        for arg in args.D:
            for var in arg:
                if '=' not in var:
                    macros[var] = ''
                else:
                    temp = var.split('=')
                    macros[temp[0]] = temp[1]

    output = args.output[0] if args.output else None
    build = args.build[0] if args.build else ''

    # Sorts out the terminal colours on Windows
    strip_colours = not args.colour
    colorama.init(strip=strip_colours)

    project = FortranProject(files=args.files,
                             exclude_files=args.exclude_files,
                             ignore_modules=args.ignore_modules,
                             macros=macros,
                             cpp_includes=args.I,
                             verbose=args.verbose,
                             use_preprocessor=not args.no_preprocessor)

    if output is not None:
        project.write_depends(filename=output,
                              overwrite=args.overwrite,
                              build=build,
                              skip_programs=args.skip_programs)

    if args.graph:
        project.make_graph()
コード例 #16
0
    def test_get_single_file(self):
        testproject = FortranProject(files="moduleA.f90")
        expected_files = ["moduleA.f90"]

        assert sorted(testproject.files) == sorted(expected_files)
コード例 #17
0
    def test_get_multiple_files(self):
        testproject = FortranProject(files=["moduleA.f90", "moduleB.f90"])
        expected_files = ["moduleA.f90", "moduleB.f90"]

        assert sorted(testproject.files) == sorted(expected_files)
コード例 #18
0
 def test_basic_creation(self):
     testproject = FortranProject()
     assert testproject.name[:4] == "data"
コード例 #19
0
    def test_get_files_with_different_extension(self):
        testproject = FortranProject()
        files = testproject.get_source(extensions=".f08")
        expected_files = ["different_ext.f08"]

        assert sorted(files) == sorted(expected_files)
コード例 #20
0
    def test_get_files_with_different_extension(self):
        testproject = FortranProject()
        files = testproject.get_source(extensions=".f08")
        expected_files = ["different_ext.f08"]

        assert sorted(files) == sorted(expected_files)