Skip to content

Commit

Permalink
Update tox.ini (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Feb 7, 2023
1 parent 8fdde32 commit dbde8df
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 60 deletions.
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ this operator.

## Developing

You can use the environments created by `tox` for development:
You can create an environment for development with `tox`:

```shell
tox --notest -e unit
source .tox/unit/bin/activate
tox devenv -e integration
source venv/bin/activate
```

### Testing

```shell
tox run -e fmt # update your code according to linting rules
tox run -e lint # code style
tox run -e unit # unit tests
tox run -m integration # integration tests
tox # runs 'lint' and 'unit' environments
tox run -e format # update your code according to linting rules
tox run -e lint # code style
tox run -e unit # unit tests
tox run -m integration # integration tests
tox # runs 'lint' and 'unit' environments
```

## Build charm
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
4 changes: 2 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import pytest
from pytest_operator.plugin import OpsTest

from tests.integration.integration_constants import SERIES_TO_VERSION
from tests.integration.read_charm_yaml import get_base_versions, get_charm_name
from .integration_constants import SERIES_TO_VERSION
from .read_charm_yaml import get_base_versions, get_charm_name


def pytest_addoption(parser):
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from tenacity import RetryError, Retrying, retry, stop_after_attempt, wait_fixed

from constants import SERVER_CONFIG_USERNAME
from tests.integration.connector import MysqlConnector

from .connector import MysqlConnector

logger = logging.getLogger(__name__)

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/high_availability/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
4 changes: 1 addition & 3 deletions tests/integration/high_availability/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import pytest
from pytest_operator.plugin import OpsTest

from tests.integration.high_availability.high_availability_helpers import (
get_application_name,
)
from .high_availability_helpers import get_application_name


@pytest.fixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pytest_operator.plugin import OpsTest
from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed

from tests.integration.helpers import (
from ..helpers import (
execute_queries_on_unit,
generate_random_string,
get_cluster_status,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/high_availability/test_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from tests.integration.helpers import (
from ..helpers import (
app_name,
cluster_name,
execute_queries_on_unit,
Expand All @@ -20,7 +20,7 @@
get_server_config_credentials,
scale_application,
)
from tests.integration.high_availability.high_availability_helpers import (
from .high_availability_helpers import (
clean_up_database_and_table,
ensure_all_units_continuous_writes_incrementing,
ensure_n_online_mysql_members,
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/high_availability/test_self_healing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed

from constants import CLUSTER_ADMIN_USERNAME, SERVER_CONFIG_USERNAME
from tests.integration.helpers import (

from ..helpers import (
cut_network_from_unit,
execute_queries_on_unit,
get_controller_machine,
Expand All @@ -31,7 +32,7 @@
wait_network_restore,
write_random_chars_to_test_table,
)
from tests.integration.high_availability.high_availability_helpers import (
from .high_availability_helpers import (
clean_up_database_and_table,
ensure_all_units_continuous_writes_incrementing,
ensure_n_online_mysql_members,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/read_charm_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import yaml

from tests.integration.integration_constants import SERIES_TO_VERSION
from .integration_constants import SERIES_TO_VERSION


def get_base_versions(path_to_charmcraft_yaml: Path) -> list[str]:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/relations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
5 changes: 3 additions & 2 deletions tests/integration/relations/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
ROOT_USERNAME,
SERVER_CONFIG_USERNAME,
)
from tests.integration.helpers import (
from utils import generate_random_password

from ..helpers import (
check_read_only_endpoints,
execute_queries_on_unit,
fetch_credentials,
Expand All @@ -29,7 +31,6 @@
rotate_credentials,
scale_application,
)
from utils import generate_random_password

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relations/test_db_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from tests.integration.helpers import (
from ..helpers import (
execute_queries_on_unit,
get_server_config_credentials,
scale_application,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relations/test_relation_mysql_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from tests.integration.helpers import (
from ..helpers import (
get_legacy_mysql_credentials,
instance_ip,
is_connection_possible,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/relations/test_shared_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import yaml
from pytest_operator.plugin import OpsTest

from tests.integration.helpers import (
from ..helpers import (
execute_queries_on_unit,
get_primary_unit,
get_server_config_credentials,
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pytest_operator.plugin import OpsTest

from constants import CLUSTER_ADMIN_USERNAME, TLS_SSL_CERT_FILE
from tests.integration.helpers import (

from .helpers import (
app_name,
get_process_pid,
get_system_user_password,
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from tenacity import Retrying, stop_after_attempt

from charm import MySQLOperatorCharm
from tests.unit.helpers import patch_network_get

from .helpers import patch_network_get


class TestCharm(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from charm import MySQLOperatorCharm
from constants import DB_RELATION_NAME
from tests.unit.helpers import patch_network_get

from .helpers import patch_network_get


class TestDatase(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_db_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from ops.testing import Harness

from charm import MySQLOperatorCharm
from tests.unit.helpers import patch_network_get

from .helpers import patch_network_get


class TestDBRouter(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_relation_mysql_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from charm import MySQLOperatorCharm
from constants import LEGACY_MYSQL, PEER
from tests.unit.helpers import patch_network_get

from .helpers import patch_network_get


class TestMariaDBRelation(unittest.TestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_shared_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from charm import MySQLOperatorCharm
from constants import LEGACY_DB_SHARED
from tests.unit.helpers import patch_network_get

from .helpers import patch_network_get


class TestSharedDBRelation(unittest.TestCase):
Expand Down
58 changes: 29 additions & 29 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
# See LICENSE file for licensing details.

[tox]
skipsdist=True
no_package = True
skip_missing_interpreters = True
envlist = lint, unit
env_list = lint, unit
labels =
integration = integration-ha, integration-db-router, integration-shared-db, \
integration-database, integration-mysql-interface, integration-healing, \
integration-tls

[vars]
src_path = {toxinidir}/src
tests_path = {toxinidir}/tests
lib_path = {toxinidir}/lib/charms/mysql
src_path = {tox_root}/src
tests_path = {tox_root}/tests
lib_path = {tox_root}/lib/charms/mysql
all_path = {[vars]src_path} {[vars]tests_path} {[vars]lib_path}

[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path}
PYTHONBREAKPOINT=ipdb.set_trace
PY_COLORS=1
passenv =
CI
PYTHONPATH
CHARM_BUILD_DIR
MODEL_SETTINGS

[testenv:fmt]
set_env =
PYTHONPATH = {tox_root}/lib:{[vars]src_path}
PYTHONBREAKPOINT=ipdb.set_trace
PY_COLORS=1
pass_env =
CI
PYTHONPATH
CHARM_BUILD_DIR
MODEL_SETTINGS

[testenv:format]
description = Apply coding style standards to code
deps =
black
Expand All @@ -53,9 +53,9 @@ allowlist_externals = /bin/bash
commands =
# uncomment the following line if this charm owns a lib
# codespell {[vars]lib_path}
codespell {toxinidir} --skip {toxinidir}/.git --skip {toxinidir}/.tox \
--skip {toxinidir}/build --skip {toxinidir}/lib --skip {toxinidir}/venv \
--skip {toxinidir}/.mypy_cache --skip {toxinidir}/icon.svg
codespell {tox_root} --skip {tox_root}/.git --skip {tox_root}/.tox \
--skip {tox_root}/build --skip {tox_root}/lib --skip {tox_root}/venv \
--skip {tox_root}/.mypy_cache --skip {tox_root}/icon.svg
# pflake8 wrapper supports config from pyproject.toml
pflake8 {[vars]all_path}
isort --check-only --diff {[vars]all_path}
Expand All @@ -67,7 +67,7 @@ description = Run unit tests
deps =
pytest
coverage[toml]
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
coverage run --source={[vars]src_path},{[vars]lib_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
Expand All @@ -77,7 +77,7 @@ commands =
description = Create build matrix for integration tests
deps =
pyyaml
passenv = GITHUB_OUTPUT
pass_env = GITHUB_OUTPUT
commands =
python -c "from tests.integration.read_charm_yaml import create_build_matrix; create_build_matrix()"

Expand All @@ -89,7 +89,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/high_availability/test_replication.py

Expand All @@ -101,7 +101,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_db_router.py

Expand All @@ -113,7 +113,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_shared_db.py

Expand All @@ -125,7 +125,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_database.py

Expand All @@ -137,7 +137,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_relation_mysql_legacy.py

Expand All @@ -149,7 +149,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/high_availability/test_self_healing.py

Expand All @@ -161,7 +161,7 @@ deps =
pytest
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/test_tls.py

Expand All @@ -175,7 +175,7 @@ deps =
pdbpp
pytest-operator
pyyaml
-r{toxinidir}/requirements.txt
-r {tox_root}/requirements.txt
commands =
pytest -v --tb native --ignore={[vars]tests_path}/unit --log-cli-level=INFO -s {posargs} -m "dev"

0 comments on commit dbde8df

Please sign in to comment.