Skip to content

Commit

Permalink
Merge branch 'issue/version-bump' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
inmantaci committed Sep 7, 2022
2 parents 118294f + b59f509 commit af5f3cc
Show file tree
Hide file tree
Showing 32 changed files with 342 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.3.3
current_version = 2.4.0
tag = False
commit = False

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
# v 2.4.0 (2022-09-07)
Changes in this release:
- Add fixture to change the Inmanta state dir to a writable location for the current user.
- Add a new '--no-strict-deps-check' option to run pytest-inmanta using the legacy check on requirements.
By default the new strict check of core will be used.

# v 2.3.3 (2022-05-18)
Changes in this release:
- Fix enum test parameters registered after pytest has loaded pytest-inmanta plugin.
Expand Down
60 changes: 0 additions & 60 deletions Jenkinsfile-integration-tests-iso3

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -173,14 +173,15 @@ The following options are available.
module to a temporary libs directory. It allows testing the current module against specific versions of dependent modules.
Using this option can speed up the tests, because the module dependencies are not downloaded multiple times.
* `--module-repo`: location to download modules from, overrides `INMANTA_MODULE_REPO`. The default value is the inmanta github organisation.
For versions of inmanta-core that support v2 modules, the repo accepts the format "[<type>:]<url>" with "type" the repository type as
For versions of inmanta-core that support v2 modules, the repo accepts the format "[\<type\>:]\<url\>" with "type" the repository type as
defined in the project config documentation. If type is omitted, git is assumed.
Multiple repos can be passed by space-separating them or by passing the parameter multiple times.
* `--install-mode`: install mode to use for modules downloaded during this test, overrides `INMANTA_INSTALL_MODE`.
* `--no-load-plugins`: Don't load plugins in the Project class. Overrides `INMANTA_NO_LOAD_PLUGINS`.
When not using this option during the testing of plugins with the `project.get_plugin_function` method,
it's possible that the module's `plugin/__init__.py` is loaded multiple times,
which can cause issues when it has side effects, as they are executed multiple times as well.
* `--no-strict-deps-check`: option to run pytest-inmanta using the legacy check(less strict) on requirements. By default the new strict will be used.

Use the generic pytest options `--log-cli-level` to show Inmanta logger to see any setup or cleanup warnings. For example,
`--log-cli-level=INFO`
Expand Down
4 changes: 4 additions & 0 deletions examples/inmanta-module-testmodulev2conflict1/MANIFEST.in
@@ -0,0 +1,4 @@
include inmanta_plugins/testmodulev2conflict1/setup.cfg
recursive-include inmanta_plugins/testmodulev2conflict1/model *.cf
graft inmanta_plugins/testmodulev2conflict1/files
graft inmanta_plugins/testmodulev2conflict1/templates
@@ -0,0 +1,11 @@
"""
Copyright 2021 Inmanta
Contact: code@inmanta.com
License: Apache 2.0
"""
from inmanta.plugins import plugin


@plugin
def myplugin(x: "int") -> "int":
return x
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions examples/inmanta-module-testmodulev2conflict1/pyproject.toml
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
14 changes: 14 additions & 0 deletions examples/inmanta-module-testmodulev2conflict1/setup.cfg
@@ -0,0 +1,14 @@
[metadata]
name = inmanta-module-testmodulev2conflict1
freeze_recursive = False
freeze_operator = ~=
version = 0.1
license = Test License

[options]
install_requires =
inmanta-module-std
lorem~=0.0.1
zip_safe = False
include_package_data = True
packages = find_namespace:
4 changes: 4 additions & 0 deletions examples/inmanta-module-testmodulev2conflict2/MANIFEST.in
@@ -0,0 +1,4 @@
include inmanta_plugins/testmodulev2conflict2/setup.cfg
recursive-include inmanta_plugins/testmodulev2conflict2/model *.cf
graft inmanta_plugins/testmodulev2conflict2/files
graft inmanta_plugins/testmodulev2conflict2/templates
@@ -0,0 +1,11 @@
"""
Copyright 2021 Inmanta
Contact: code@inmanta.com
License: Apache 2.0
"""
from inmanta.plugins import plugin


@plugin
def myplugin(x: "int") -> "int":
return x
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions examples/inmanta-module-testmodulev2conflict2/pyproject.toml
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
14 changes: 14 additions & 0 deletions examples/inmanta-module-testmodulev2conflict2/setup.cfg
@@ -0,0 +1,14 @@
[metadata]
name = inmanta-module-testmodulev2conflict2
freeze_recursive = False
freeze_operator = ~=
version = 0.1
license = Test License

[options]
install_requires =
inmanta-module-std
lorem~=0.1.1
zip_safe = False
include_package_data = True
packages = find_namespace:
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions examples/test_conflict_dependencies/module.yml
@@ -0,0 +1,8 @@
author: Inmanta
author_email: code@inmanta.com
description: module that test what happens when its dependencies conflict
license: ASL 2.0
copyright: 2021 Inmanta
name: test_conflict_dependencies
version: 0.0.1
compiler_version: 2019.3
17 changes: 17 additions & 0 deletions examples/test_conflict_dependencies/plugins/__init__.py
@@ -0,0 +1,17 @@
"""
Copyright 2021 Inmanta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contact: code@inmanta.com
"""
7 changes: 7 additions & 0 deletions examples/test_conflict_dependencies/requirements.dev.txt
@@ -0,0 +1,7 @@
pytest-inmanta
flake8
flake8-black
flake8-isort>3.0.0
flake8-copyright
isort
black
2 changes: 2 additions & 0 deletions examples/test_conflict_dependencies/requirements.txt
@@ -0,0 +1,2 @@
inmanta-module-testmodulev2conflict1
inmanta-module-testmodulev2conflict2
Empty file.
21 changes: 21 additions & 0 deletions examples/test_conflict_dependencies/tests/test_basics.py
@@ -0,0 +1,21 @@
"""
Copyright 2021 Inmanta
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contact: code@inmanta.com
"""


def test_basics(project):
project.compile("import test_conflict_dependencies")
Empty file added pyproject.toml
Empty file.
12 changes: 12 additions & 0 deletions pytest_inmanta/parameters.py
Expand Up @@ -63,6 +63,18 @@
group=param_group,
)

inm_no_strict_deps_check = BooleanTestParameter(
argument="--no-strict-deps-check",
environment_variable="INMANTA_NO_STRICT_DEPS_CHECKS",
usage=(
"Tell pytest-inmanta to run without using the deps check after module installation."
" When using the dependency check, an error is raised if there are conflicting requirements"
" when disabling the check, the less strict legacy behavior is used instead."
),
default=False,
group=param_group,
)


# This is the legacy module repo option
# TODO remove this in next major version bump
Expand Down
51 changes: 46 additions & 5 deletions pytest_inmanta/plugin.py
Expand Up @@ -43,7 +43,9 @@

import inmanta.ast
from inmanta import compiler, config, const, module, plugins, protocol
from inmanta.agent import cache, handler
from inmanta.agent import cache
from inmanta.agent import config as inmanta_config
from inmanta.agent import handler
from inmanta.agent import io as agent_io
from inmanta.agent.handler import HandlerContext, ResourceHandler
from inmanta.const import ResourceState
Expand All @@ -55,14 +57,23 @@
from inmanta.resources import Resource

if typing.TYPE_CHECKING:
# Local type stub for mypy that works with both pytest < 7 and pytest >=7
# https://docs.pytest.org/en/7.1.x/_modules/_pytest/legacypath.html#TempdirFactory
import py
from inmanta.agent.io.local import IOBase

class TempdirFactory:
def mktemp(self, path: str) -> py.path.local:
...


from .handler import DATA
from .parameters import (
inm_install_mode,
inm_mod_in_place,
inm_mod_repo,
inm_no_load_plugins,
inm_no_strict_deps_check,
inm_venv,
)
from .test_parameter import ParameterNotSetException, TestParameterRegistry
Expand Down Expand Up @@ -125,7 +136,7 @@ def inmanta_plugins(

@pytest.fixture()
def project(
project_shared: "Project", capsys: "CaptureFixture"
project_shared: "Project", capsys: "CaptureFixture", set_inmanta_state_dir: None
) -> typing.Iterator["Project"]:
DATA.clear()
project_shared.clean()
Expand All @@ -136,7 +147,9 @@ def project(

@pytest.fixture()
def project_no_plugins(
project_shared_no_plugins: "Project", capsys: "CaptureFixture"
project_shared_no_plugins: "Project",
capsys: "CaptureFixture",
set_inmanta_state_dir: None,
) -> typing.Iterator["Project"]:
warnings.warn(
DeprecationWarning(
Expand Down Expand Up @@ -269,7 +282,9 @@ def project_factory(request: pytest.FixtureRequest) -> typing.Callable[[], "Proj

def create_project(**kwargs: object):
load_plugins = not inm_no_load_plugins.resolve(request.config)
no_strict_deps_check = inm_no_strict_deps_check.resolve(request.config)
extended_kwargs: typing.Dict[str, object] = {
"no_strict_deps_check": no_strict_deps_check,
"load_plugins": load_plugins,
"env_path": env_dir,
**kwargs,
Expand Down Expand Up @@ -593,6 +608,7 @@ def __init__(
project_dir: str,
env_path: str,
load_plugins: typing.Optional[bool] = True,
no_strict_deps_check: typing.Optional[bool] = False,
) -> None:
"""
:param project_dir: Directory containing the Inmanta project.
Expand All @@ -601,6 +617,7 @@ def __init__(
"""
self._test_project_dir = project_dir
self._env_path = env_path
self.no_strict_deps_check = no_strict_deps_check
self._stdout: typing.Optional[str] = None
self._stderr: typing.Optional[str] = None
self.types: typing.Optional[typing.Dict[str, inmanta.ast.Type]] = None
Expand Down Expand Up @@ -651,7 +668,7 @@ def init(self, capsys: "CaptureFixture") -> None:

def _create_project_and_load(self, model: str) -> module.Project:
"""
This method doesn the following:
This method does the following:
* Add the given model file to the Inmanta project
* Install the module dependencies
* Load the project
Expand All @@ -666,12 +683,20 @@ def _create_project_and_load(self, model: str) -> module.Project:
module.Project.__init__
)
# The venv_path parameter only exists on ISO5+

extra_kwargs_init = (
{"venv_path": self._env_path}
if "venv_path" in signature_init.parameters.keys()
else {}
)
test_project = module.Project(self._test_project_dir, **extra_kwargs_init)

if "strict_deps_check" in signature_init.parameters.keys():
extra_kwargs_init["strict_deps_check"] = not self.no_strict_deps_check

test_project = module.Project(
self._test_project_dir,
**extra_kwargs_init,
)

ProjectLoader.load(test_project)

Expand Down Expand Up @@ -1130,3 +1155,19 @@ def finalize_handler(self, handler: ResourceHandler) -> None:
def finalize_all_handlers(self) -> None:
for handler_instance in self._handlers:
self.finalize_handler(handler_instance)


@pytest.fixture(scope="function")
def inmanta_state_dir(tmpdir_factory: "TempdirFactory") -> Iterator[str]:
"""
This fixture can be overridden in the conftest of any individual project
in order to set the Inmanta state directory at the desired level.
"""
inmanta_state_dir = tmpdir_factory.mktemp("inmanta_state_dir")
yield str(inmanta_state_dir)
inmanta_state_dir.remove()


@pytest.fixture
def set_inmanta_state_dir(inmanta_state_dir: str) -> None:
inmanta_config.state_dir.set(inmanta_state_dir)
5 changes: 3 additions & 2 deletions requirements.txt
@@ -1,5 +1,6 @@
inmanta-dev-dependencies==1.76.0; python_version <= '3.6'
inmanta-dev-dependencies==2.17.0; python_version > '3.6'
inmanta-dev-dependencies==2.34.0; python_version > '3.6'
inmanta-core
pydantic==1.9.0
pydantic==1.9.2; python_version <= '3.6'
pydantic==1.10.2; python_version > '3.6'
pyyaml==6.0
2 changes: 2 additions & 0 deletions setup.cfg
Expand Up @@ -26,6 +26,8 @@ copyright-check=True
copyright-author=Inmanta
# C errors are not selected by default, so add them to the selection
select = E,F,W,C,BLK,I
# make sure projects in examples dir are never considered as separate projects rather than depending on how check is invoked
black-config=pyproject.toml

[isort]
profile=black
Expand Down

0 comments on commit af5f3cc

Please sign in to comment.