plain.pytest 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ ## Plain is released under the BSD 3-Clause License
2
+
3
+ BSD 3-Clause License
4
+
5
+ Copyright (c) 2023, Dropseed, LLC
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this
11
+ list of conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ 3. Neither the name of the copyright holder nor the names of its
18
+ contributors may be used to endorse or promote products derived from
19
+ this software without specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.1
2
+ Name: plain.pytest
3
+ Version: 0.1.0
4
+ Summary: Testing for Plain
5
+ Home-page: https://plainframework.com
6
+ License: BSD-3-Clause
7
+ Author: Dave Gaeddert
8
+ Author-email: dave.gaeddert@dropseed.dev
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Requires-Dist: click (>=8.0.0)
18
+ Requires-Dist: pytest (>=7.0.0,<8.0.0)
19
+ Project-URL: Documentation, https://plainframework.com/docs/
20
+ Project-URL: Repository, https://github.com/dropseed/plain
21
+ Description-Content-Type: text/markdown
22
+
23
+ <!-- This file is compiled from plain-pytest/plain/pytest/README.md. Do not edit this file directly. -->
24
+
25
+ ## Testing - pytest
26
+
27
+ Write and run tests with pytest.
28
+
29
+ Django includes its own test runner and [unittest](https://docs.python.org/3/library/unittest.html#module-unittest) classes.
30
+ But a lot of people (myself included) prefer [pytest](https://docs.pytest.org/en/latest/contents.html).
31
+
32
+ In Plain I've removed the Django test runner and a lot of the implications that come with it.
33
+ There are a few utilities that remain to make testing easier,
34
+ and `plain-test` is a wrapper around `pytest`.
35
+
@@ -0,0 +1,12 @@
1
+ <!-- This file is compiled from plain-pytest/plain/pytest/README.md. Do not edit this file directly. -->
2
+
3
+ ## Testing - pytest
4
+
5
+ Write and run tests with pytest.
6
+
7
+ Django includes its own test runner and [unittest](https://docs.python.org/3/library/unittest.html#module-unittest) classes.
8
+ But a lot of people (myself included) prefer [pytest](https://docs.pytest.org/en/latest/contents.html).
9
+
10
+ In Plain I've removed the Django test runner and a lot of the implications that come with it.
11
+ There are a few utilities that remain to make testing easier,
12
+ and `plain-test` is a wrapper around `pytest`.
@@ -0,0 +1,10 @@
1
+ ## Testing - pytest
2
+
3
+ Write and run tests with pytest.
4
+
5
+ Django includes its own test runner and [unittest](https://docs.python.org/3/library/unittest.html#module-unittest) classes.
6
+ But a lot of people (myself included) prefer [pytest](https://docs.pytest.org/en/latest/contents.html).
7
+
8
+ In Plain I've removed the Django test runner and a lot of the implications that come with it.
9
+ There are a few utilities that remain to make testing easier,
10
+ and `plain-test` is a wrapper around `pytest`.
@@ -0,0 +1,3 @@
1
+ from .cli import cli
2
+
3
+ __all__ = ["cli"]
@@ -0,0 +1,48 @@
1
+ import os
2
+ import subprocess
3
+ import sys
4
+
5
+ import click
6
+
7
+ from plain.runtime import settings
8
+
9
+
10
+ @click.command(
11
+ context_settings={
12
+ "ignore_unknown_options": True,
13
+ }
14
+ )
15
+ @click.argument("pytest_args", nargs=-1, type=click.UNPROCESSED)
16
+ def cli(pytest_args):
17
+ """Run tests with pytest"""
18
+
19
+ plain_tmp_dir = str(settings.PLAIN_TEMP_PATH)
20
+
21
+ if not os.path.exists(os.path.join(plain_tmp_dir, ".gitignore")):
22
+ os.makedirs(plain_tmp_dir, exist_ok=True)
23
+ with open(os.path.join(plain_tmp_dir, ".gitignore"), "w") as f:
24
+ f.write("*\n")
25
+
26
+ # Turn deprecation warnings into errors
27
+ # if "-W" not in pytest_args:
28
+ # pytest_args = list(pytest_args) # Make sure it's a list instead of tuple
29
+ # pytest_args.append("-W")
30
+ # pytest_args.append("error::DeprecationWarning")
31
+
32
+ os.environ.setdefault("PLAIN_ENV", "test")
33
+
34
+ click.secho(f"Running pytest with PLAIN_ENV={os.environ['PLAIN_ENV']}", bold=True)
35
+
36
+ result = subprocess.run(
37
+ [
38
+ "pytest",
39
+ *pytest_args,
40
+ ],
41
+ env={
42
+ **os.environ,
43
+ },
44
+ )
45
+
46
+ if result.returncode:
47
+ # Can be invoked by pre-commit, so only exit if it fails
48
+ sys.exit(result.returncode)
@@ -0,0 +1,26 @@
1
+ import pytest
2
+ from plain.runtime import settings, setup
3
+ from plain.test.client import Client, RequestFactory
4
+
5
+
6
+ def pytest_configure(config):
7
+ # Run Plain setup before anything else
8
+ setup()
9
+
10
+
11
+ @pytest.fixture(autouse=True, scope="session")
12
+ def _allowed_hosts_testserver():
13
+ # Add testserver to ALLOWED_HOSTS so the test client can make requests
14
+ settings.ALLOWED_HOSTS = [*settings.ALLOWED_HOSTS, "testserver"]
15
+
16
+
17
+ @pytest.fixture()
18
+ def client() -> Client:
19
+ """A Plain test client instance."""
20
+ return Client()
21
+
22
+
23
+ @pytest.fixture()
24
+ def request_factory() -> RequestFactory:
25
+ """A Plain RequestFactory instance."""
26
+ return RequestFactory()
@@ -0,0 +1,36 @@
1
+ [tool.poetry]
2
+
3
+ name = "plain.pytest"
4
+ packages = [
5
+ { include = "plain" },
6
+ ]
7
+
8
+ version = "0.1.0"
9
+ description = "Testing for Plain"
10
+ authors = ["Dave Gaeddert <dave.gaeddert@dropseed.dev>"]
11
+ license = "BSD-3-Clause"
12
+ readme = "README.md"
13
+ homepage = "https://plainframework.com"
14
+ documentation = "https://plainframework.com/docs/"
15
+ repository = "https://github.com/dropseed/plain"
16
+
17
+ # Make the CLI available without adding to INSTALLED_APPS
18
+ [tool.poetry.plugins."plain.cli"]
19
+ "test" = "plain.pytest:cli"
20
+
21
+ # Automatically sets this up with pytest
22
+ [tool.poetry.plugins."pytest11"]
23
+ "plain" = "plain.pytest.plugin"
24
+
25
+
26
+ [tool.poetry.dependencies]
27
+ python = "^3.8"
28
+ click = ">=8.0.0"
29
+ pytest = "^7.0.0"
30
+
31
+ [tool.poetry.dev-dependencies]
32
+ ipdb = "^0.13.9"
33
+
34
+ [build-system]
35
+ requires = ["poetry-core>=1.0.0"]
36
+ build-backend = "poetry.core.masonry.api"