def test_module_v2_name_underscore(inmanta_module_v2: InmantaModule,
                                   underscore: bool):
    """
    Test module v2 metadata parsing with respect to module naming rules about dashes and underscores.
    """
    separator: str = "_" if underscore else "-"
    inmanta_module_v2.write_metadata_file(f"""
[metadata]
name = inmanta-module-my{separator}mod
version = 1.2.3
license = Apache 2.0

[options]
install_requires =
  inmanta-modules-net ~=0.2.4
  inmanta-modules-std >1.0,<2.5

  cookiecutter~=1.7.0
  cryptography>1.0,<3.5
packages = find_namespace:
        """)
    if underscore:
        with pytest.raises(InvalidModuleException):
            module.ModuleV2(None, inmanta_module_v2.get_root_dir_of_module())
    else:
        module.ModuleV2(None, inmanta_module_v2.get_root_dir_of_module())
Exemplo n.º 2
0
def test_get_requirements(
    modules_dir: str,
    modules_v2_dir: str,
    v1_module: bool,
    all_python_requirements: List[str],
    strict_python_requirements: List[str],
    module_requirements: List[str],
    module_v2_requirements: List[str],
) -> None:
    """
    Test the different methods to get the requirements of a module.
    """
    module_name = "many_dependencies"

    if v1_module:
        module_dir = os.path.join(modules_dir, module_name)
        mod = module.ModuleV1(module.DummyProject(autostd=False), module_dir)
    else:
        module_dir = os.path.join(modules_v2_dir, module_name)
        mod = module.ModuleV2(module.DummyProject(autostd=False), module_dir)

    assert set(mod.get_all_python_requirements_as_list()) == set(
        all_python_requirements)
    assert set(mod.get_strict_python_requirements_as_list()) == set(
        strict_python_requirements)
    assert set(mod.get_module_requirements()) == set(module_requirements)
    assert set(mod.get_module_v2_requirements()) == set(module_v2_requirements)
    assert set(mod.requires()) == set(
        module.InmantaModuleRequirement.parse(req)
        for req in module_requirements)
def test_moduletool_create_v2(tmp_working_dir: py.path.local) -> None:
    """
    Verify that `inmanta module create` creates a valid v2 module with expected parameters.
    """
    ModuleTool().execute(
        "create", argparse.Namespace(name="my_module", v1=False,
                                     no_input=True))
    mod: module.ModuleV2 = module.ModuleV2(
        project=None, path=str(tmp_working_dir.join("my-module")))
    assert mod.name == "my_module"
Exemplo n.º 4
0
 def test_non_matching_name_v2_module(self) -> None:
     """
     Make sure the warning regarding directory name does not trigger for v2 modules, as it is not relevant there.
     """
     template_dir: str = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), "data", "modules_v2",
         "minimalv2module")
     with tempfile.TemporaryDirectory() as tmpdir:
         mod_dir: str = os.path.join(tmpdir, "not-the-module-name")
         module_from_template(template_dir, mod_dir)
         module.ModuleV2(project=module.DummyProject(), path=mod_dir)
         self.handler.flush()
         assert self.stream.getvalue().strip() == ""
def test_module_v2_metadata(inmanta_module_v2: InmantaModule) -> None:
    inmanta_module_v2.write_metadata_file("""
[metadata]
name = inmanta-module-mod1
version = 1.2.3
license = Apache 2.0

[options]
install_requires =
  inmanta-modules-net ~=0.2.4
  inmanta-modules-std >1.0,<2.5

  cookiecutter~=1.7.0
  cryptography>1.0,<3.5
        """)
    mod: module.ModuleV2 = module.ModuleV2(
        None, inmanta_module_v2.get_root_dir_of_module())
    assert mod.metadata.name == "inmanta-module-mod1"
    assert mod.metadata.version == "1.2.3"
    assert mod.metadata.license == "Apache 2.0"