Skip to content

Commit

Permalink
refactor: Remove unnecessary namespacing of fixtures. (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin committed Sep 16, 2022
1 parent 3254bd8 commit 51d9785
Show file tree
Hide file tree
Showing 32 changed files with 81 additions and 86 deletions.
2 changes: 1 addition & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fixture Functions
:members: create_mongo_fixture, create_mysql_fixture, create_postgres_fixture, create_redis_fixture, create_redshift_fixture, create_sqlite_fixture, Rows, Statements, StaticStatements


.. automodule:: pytest_mock_resources.fixture.database.generic
.. automodule:: pytest_mock_resources.fixture.credentials
:members: Credentials

Fixture Config
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-mock-resources"
version = "2.5.1"
version = "2.5.2"
description = "A pytest plugin for easily instantiating reproducible mock resources."
authors = [
"Omar Khan <oakhan3@gmail.com>",
Expand Down
8 changes: 4 additions & 4 deletions src/pytest_mock_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
RedisConfig,
RedshiftConfig,
)
from pytest_mock_resources.fixture.database import (
from pytest_mock_resources.fixture import (
create_mongo_fixture,
create_mysql_fixture,
create_postgres_fixture,
create_redis_fixture,
create_redshift_fixture,
create_sqlite_fixture,
Credentials,
pmr_mongo_config,
pmr_mongo_container,
pmr_mysql_config,
Expand All @@ -23,16 +24,14 @@
pmr_redis_container,
pmr_redshift_config,
pmr_redshift_container,
Rows,
Statements,
StaticStatements,
)
from pytest_mock_resources.hooks import ( # noqa
pytest_addoption,
pytest_configure,
pytest_itemcollected,
pytest_sessionfinish,
)
from pytest_mock_resources.sqlalchemy import Rows, Statements, StaticStatements

__all__ = [
"get_container",
Expand All @@ -47,6 +46,7 @@
"create_redis_fixture",
"create_redshift_fixture",
"create_sqlite_fixture",
"Credentials",
"pmr_mongo_config",
"pmr_mongo_container",
"pmr_mysql_config",
Expand Down
53 changes: 46 additions & 7 deletions src/pytest_mock_resources/fixture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
import uuid
from pytest_mock_resources.fixture.credentials import Credentials
from pytest_mock_resources.fixture.mongo import (
create_mongo_fixture,
pmr_mongo_config,
pmr_mongo_container,
)
from pytest_mock_resources.fixture.mysql import (
create_mysql_fixture,
pmr_mysql_config,
pmr_mysql_container,
)
from pytest_mock_resources.fixture.postgresql import (
create_postgres_fixture,
pmr_postgres_config,
pmr_postgres_container,
)
from pytest_mock_resources.fixture.redis import (
create_redis_fixture,
pmr_redis_config,
pmr_redis_container,
)
from pytest_mock_resources.fixture.redshift import (
create_redshift_fixture,
pmr_redshift_config,
pmr_redshift_container,
)
from pytest_mock_resources.fixture.sqlite import create_sqlite_fixture


def generate_fixture_id(enabled: bool = True, name=""):
if enabled:
uuid_str = str(uuid.uuid4()).replace("-", "_")
return "_".join(["pmr_template", name, uuid_str])
return None
__all__ = [
"create_mongo_fixture",
"create_mysql_fixture",
"create_postgres_fixture",
"create_redis_fixture",
"create_redshift_fixture",
"create_sqlite_fixture",
"Credentials",
"pmr_mongo_config",
"pmr_mongo_container",
"pmr_mysql_config",
"pmr_mysql_container",
"pmr_postgres_config",
"pmr_postgres_container",
"pmr_redis_config",
"pmr_redis_container",
"pmr_redshift_config",
"pmr_redshift_container",
]
8 changes: 8 additions & 0 deletions src/pytest_mock_resources/fixture/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import uuid


def generate_fixture_id(enabled: bool = True, name=""):
if enabled:
uuid_str = str(uuid.uuid4()).replace("-", "_")
return "_".join(["pmr_template", name, uuid_str])
return None
26 changes: 0 additions & 26 deletions src/pytest_mock_resources/fixture/database/__init__.py

This file was deleted.

22 changes: 0 additions & 22 deletions src/pytest_mock_resources/fixture/database/relational/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest_mock_resources.compat import pymongo
from pytest_mock_resources.container.base import get_container
from pytest_mock_resources.container.mongo import MongoConfig
from pytest_mock_resources.fixture.database.generic import assign_fixture_credentials
from pytest_mock_resources.fixture.credentials import assign_fixture_credentials


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from pytest_mock_resources.container.base import get_container
from pytest_mock_resources.container.mysql import get_sqlalchemy_engine, MysqlConfig
from pytest_mock_resources.fixture.database.generic import assign_fixture_credentials
from pytest_mock_resources.fixture.database.relational.generic import EngineManager
from pytest_mock_resources.fixture.credentials import assign_fixture_credentials
from pytest_mock_resources.sqlalchemy import EngineManager


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

from pytest_mock_resources.container.base import get_container
from pytest_mock_resources.container.postgres import get_sqlalchemy_engine, PostgresConfig
from pytest_mock_resources.fixture import generate_fixture_id
from pytest_mock_resources.fixture.database.generic import assign_fixture_credentials
from pytest_mock_resources.fixture.database.relational.generic import (
bifurcate_actions,
EngineManager,
normalize_actions,
)
from pytest_mock_resources.fixture.base import generate_fixture_id
from pytest_mock_resources.fixture.credentials import assign_fixture_credentials
from pytest_mock_resources.sqlalchemy import bifurcate_actions, EngineManager, normalize_actions

log = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest_mock_resources.compat import redis
from pytest_mock_resources.container.base import get_container
from pytest_mock_resources.container.redis import RedisConfig
from pytest_mock_resources.fixture.database.generic import assign_fixture_credentials
from pytest_mock_resources.fixture.credentials import assign_fixture_credentials


@pytest.fixture(scope="session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pytest_mock_resources.container.base import get_container
from pytest_mock_resources.container.redshift import get_sqlalchemy_engine, RedshiftConfig
from pytest_mock_resources.fixture import generate_fixture_id
from pytest_mock_resources.fixture.database.relational.postgresql import create_engine_manager
from pytest_mock_resources.fixture.base import generate_fixture_id
from pytest_mock_resources.fixture.postgresql import create_engine_manager
from pytest_mock_resources.patch.redshift import psycopg2, sqlalchemy


Expand Down Expand Up @@ -69,7 +69,7 @@ def create_redshift_fixture(
to bad default behavior).
"""

from pytest_mock_resources.fixture.database.relational.redshift.udf import REDSHIFT_UDFS
from pytest_mock_resources.fixture.redshift.udf import REDSHIFT_UDFS

fixture_id = generate_fixture_id(enabled=template_database, name="pg")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sqlalchemy import text

from pytest_mock_resources.fixture.database import Statements
from pytest_mock_resources.sqlalchemy import Statements


@enum.unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import sqltypes

from pytest_mock_resources.fixture.database.generic import assign_fixture_credentials
from pytest_mock_resources.fixture.database.relational.generic import EngineManager
from pytest_mock_resources.fixture.credentials import assign_fixture_credentials
from pytest_mock_resources.sqlalchemy import EngineManager


class PMRSQLiteDDLCompiler(sqlite_base.SQLiteDDLCompiler):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/fixture/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import pytest

pytest.register_assert_rewrite("tests.fixture.database")
pytest.register_assert_rewrite("tests.fixture.redshift.utils")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pytest_mock_resources.compat import boto3, moto
from pytest_mock_resources.compat.sqlalchemy import declarative_base
from tests import skip_if_sqlalchemy2
from tests.fixture.database import (
from tests.fixture.redshift.utils import (
COPY_TEMPLATE,
data_columns,
fetch_values_from_table_and_assert,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import text

from pytest_mock_resources import create_postgres_fixture, create_redshift_fixture
from tests.fixture.database import (
from tests.fixture.redshift.utils import (
copy_fn_to_test_create_engine_patch,
copy_fn_to_test_psycopg2_connect_patch,
copy_fn_to_test_psycopg2_connect_patch_as_context_manager,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytest_mock_resources import create_redshift_fixture
from pytest_mock_resources.compat import moto
from tests import skip_if_sqlalchemy2
from tests.fixture.database import (
from tests.fixture.redshift.utils import (
fetch_values_from_s3_and_assert,
randomcase,
setup_table_and_insert_data,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
create_redshift_fixture,
create_sqlite_fixture,
)
from pytest_mock_resources.fixture.database.relational.generic import EngineManager
from pytest_mock_resources.sqlalchemy import EngineManager
from tests import skip_if_not_sqlalchemy2

sqlite = create_sqlite_fixture()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pytest_mock_resources import create_postgres_fixture, create_sqlite_fixture, Rows
from pytest_mock_resources.compat.sqlalchemy import declarative_base, select
from pytest_mock_resources.fixture.database.relational.generic import identify_matching_tables
from pytest_mock_resources.sqlalchemy import identify_matching_tables
from tests import skip_if_not_sqlalchemy2, skip_if_sqlalchemy2

Base = declarative_base()
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pytest_mock_resources import create_postgres_fixture
from pytest_mock_resources.compat.sqlalchemy import declarative_base
from pytest_mock_resources.container.postgres import get_sqlalchemy_engine
from pytest_mock_resources.fixture.database.relational.postgresql import _produce_clean_database
from pytest_mock_resources.fixture.postgresql import _produce_clean_database

Base = declarative_base()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pytest_mock_resources import create_postgres_fixture, create_sqlite_fixture, Rows
from pytest_mock_resources.compat.sqlalchemy import declarative_base, select
from pytest_mock_resources.fixture.database.relational.sqlite import utc
from pytest_mock_resources.fixture.sqlite import utc

Base = declarative_base()

Expand Down
File renamed without changes.

0 comments on commit 51d9785

Please sign in to comment.