csspin-python 2.1.0__py3-none-any.whl → 3.0.0__py3-none-any.whl

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.
csspin_python/behave.py CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  import contextlib
22
22
  import sys
23
- from typing import Generator
23
+ from typing import Generator, Iterable
24
24
 
25
25
  from csspin import config, die, info, option, rmtree, setenv, sh, task, writetext
26
26
  from csspin.tree import ConfigTree
@@ -67,16 +67,16 @@ def configure(cfg: ConfigTree) -> None:
67
67
  cfg.behave.opts.append("--tags=~windows")
68
68
 
69
69
 
70
- def create_coverage_pth(cfg: ConfigTree) -> str: # pylint: disable=unused-argument
70
+ def create_coverage_pth(cfg: ConfigTree) -> Path: # pylint: disable=unused-argument
71
71
  """Creating the coverage path file and returning its path"""
72
- coverage_pth_path = cfg.python.site_packages / "coverage.pth"
72
+ coverage_pth_path: Path = cfg.python.site_packages / "coverage.pth"
73
73
  info(f"Create {coverage_pth_path}")
74
74
  writetext(coverage_pth_path, "import coverage; coverage.process_startup()")
75
75
  return coverage_pth_path
76
76
 
77
77
 
78
78
  @contextlib.contextmanager
79
- def with_coverage(cfg: ConfigTree) -> Generator:
79
+ def with_coverage(cfg: ConfigTree) -> Generator[None, None, None]:
80
80
  """Context-manager enabling to run coverage"""
81
81
  coverage_pth = ""
82
82
  try:
@@ -95,28 +95,28 @@ def with_coverage(cfg: ConfigTree) -> Generator:
95
95
 
96
96
  @task(when="cept")
97
97
  def behave( # pylint: disable=too-many-arguments,too-many-positional-arguments
98
- cfg,
99
- instance: option(
98
+ cfg: ConfigTree,
99
+ instance: option( # type: ignore[valid-type]
100
100
  "-i", # noqa: F821
101
101
  "--instance", # noqa: F821
102
102
  help="Directory of the CONTACT Elements instance.", # noqa: F722
103
103
  ),
104
- coverage: option(
104
+ coverage: option( # type: ignore[valid-type]
105
105
  "-c", # noqa: F821
106
106
  "--coverage", # noqa: F821
107
107
  is_flag=True,
108
108
  help="Run the tests while collecting coverage.", # noqa: F722
109
109
  ),
110
- debug: option(
110
+ debug: option( # type: ignore[valid-type]
111
111
  "--debug", is_flag=True, help="Start debug server." # noqa: F722,F821
112
112
  ),
113
- with_test_report: option(
113
+ with_test_report: option( # type: ignore[valid-type]
114
114
  "--with-test-report", # noqa: F722
115
115
  is_flag=True,
116
116
  help="Create a test execution report.", # noqa: F722
117
117
  ),
118
- args,
119
- ):
118
+ args: Iterable[str],
119
+ ) -> None:
120
120
  """Run Gherkin tests using behave."""
121
121
  # pylint: disable=missing-function-docstring
122
122
  coverage_enabled = coverage or cfg.behave.coverage
csspin_python/devpi.py CHANGED
@@ -18,7 +18,10 @@
18
18
  """Module implementing the devpi plugin for spin"""
19
19
 
20
20
 
21
+ from typing import Iterable
22
+
21
23
  from csspin import Command, config, die, exists, readyaml, setenv, sh, task
24
+ from csspin.tree import ConfigTree
22
25
 
23
26
  defaults = config(
24
27
  formats=["bdist_wheel"],
@@ -34,13 +37,13 @@ defaults = config(
34
37
  )
35
38
 
36
39
 
37
- def init(cfg): # pylint: disable=unused-argument
40
+ def init(cfg: ConfigTree) -> None: # pylint: disable=unused-argument
38
41
  """Sets some environment variables"""
39
42
  setenv(DEVPI_VENV="{python.venv}", DEVPI_CLIENTDIR="{spin.spin_dir}/devpi")
40
43
 
41
44
 
42
45
  @task("devpi:upload")
43
- def upload(cfg):
46
+ def upload(cfg: ConfigTree) -> None:
44
47
  """Upload project wheel to a package server."""
45
48
  if not cfg.devpi.user:
46
49
  die("devpi.user is required!")
@@ -68,7 +71,7 @@ def upload(cfg):
68
71
 
69
72
 
70
73
  @task()
71
- def devpi(cfg, args):
74
+ def devpi(cfg: ConfigTree, args: Iterable[str]) -> None:
72
75
  """Run the 'devpi' command inside the project's virtual environment.
73
76
 
74
77
  All command line arguments are simply passed through to 'devpi'.
@@ -17,7 +17,10 @@
17
17
 
18
18
  """Module implementing the playwright plugin for spin"""
19
19
 
20
- from csspin import Path, Verbosity, config, die, option, setenv, sh, task
20
+ from typing import Iterable
21
+
22
+ from csspin import Path, Verbosity, config, die, option, setenv, sh, task, warn
23
+ from csspin.tree import ConfigTree
21
24
 
22
25
  defaults = config(
23
26
  browsers_path="{spin.data}/playwright_browsers",
@@ -50,30 +53,40 @@ defaults = config(
50
53
 
51
54
  @task(when="cept")
52
55
  def playwright( # pylint: disable=too-many-arguments,too-many-positional-arguments
53
- cfg,
54
- instance: option(
56
+ cfg: ConfigTree,
57
+ instance: option( # type: ignore[valid-type]
55
58
  "-i", # noqa: F821
56
59
  "--instance", # noqa: F821
57
60
  default=None,
58
61
  help="Directory of the CONTACT Elements instance.", # noqa: F722
59
62
  ),
60
- coverage: option(
63
+ coverage: option( # type: ignore[valid-type]
61
64
  "-c", # noqa: F821
62
65
  "--coverage", # noqa: F821
63
66
  is_flag=True,
64
67
  help="Run the tests while collecting coverage.", # noqa: F722
65
68
  ),
66
- debug: option(
69
+ debug: option( # type: ignore[valid-type]
67
70
  "--debug", is_flag=True, help="Start debug server." # noqa: F722,F821
68
71
  ),
69
- with_test_report: option(
72
+ with_test_report: option( # type: ignore[valid-type]
70
73
  "--with-test-report", # noqa: F722
71
74
  is_flag=True,
72
75
  help="Create a test execution report.", # noqa: F722
73
76
  ),
74
- args,
75
- ):
77
+ args: Iterable[str],
78
+ ) -> None:
76
79
  """Run the playwright tests with pytest."""
80
+ if cfg.pytest.playwright.enabled:
81
+ # This prevents the playwright tests from being run twice.
82
+ warn(
83
+ (
84
+ "The 'playwright' task has been skipped, as the playwright tests"
85
+ " are already being run by the csspin_python.pytest plugin."
86
+ " Please stop using the csspin_python.playwright plugin."
87
+ )
88
+ )
89
+ return
77
90
  setenv(
78
91
  PLAYWRIGHT_BROWSERS_PATH=cfg.playwright.browsers_path,
79
92
  PACKAGE_NAME=cfg.spin.project_name,
@@ -113,7 +126,7 @@ def playwright( # pylint: disable=too-many-arguments,too-many-positional-argume
113
126
  sh(*cmd, *opts, *args, *cfg.playwright.tests)
114
127
 
115
128
 
116
- def _download_playwright_browsers(cfg):
129
+ def _download_playwright_browsers(cfg: ConfigTree) -> None:
117
130
  """Let playwright install the browsers"""
118
131
  sh(
119
132
  f"playwright install {' '.join(cfg.playwright.browsers)}",
@@ -121,6 +134,17 @@ def _download_playwright_browsers(cfg):
121
134
  )
122
135
 
123
136
 
124
- def provision(cfg):
137
+ def finalize_provision(cfg: ConfigTree) -> None:
125
138
  """Install playwright browsers during provisioning"""
126
139
  _download_playwright_browsers(cfg)
140
+
141
+
142
+ def init(cfg: ConfigTree) -> None: # pylint: disable=unused-argument
143
+ """Show deprecation notice in every spin call"""
144
+ warn(
145
+ (
146
+ "The csspin_python.playwright plugin will be removed with the next major release."
147
+ " Please use csspin_python.pytest with the 'pytest.playwright.enabled=True' setting"
148
+ " instead and stop using the csspin_python.playwright plugin."
149
+ )
150
+ )
@@ -5,7 +5,9 @@
5
5
  playwright:
6
6
  type: object
7
7
  help: |
8
- The pytest plugin provides the full pytest experience for spin.
8
+ The pytest plugin provides the full pytest experience for spin. This
9
+ plugin is deprecated, use the pytest plugin with the
10
+ 'pytest.playwright.enabled=true' setting instead.
9
11
  properties:
10
12
  browsers_path:
11
13
  type: path
csspin_python/pytest.py CHANGED
@@ -18,7 +18,10 @@
18
18
  """Module implementing the pytest plugin for spin"""
19
19
 
20
20
 
21
- from csspin import Path, Verbosity, config, die, option, setenv, sh, task
21
+ from typing import Iterable
22
+
23
+ from csspin import Path, Verbosity, config, die, interpolate1, option, setenv, sh, task
24
+ from csspin.tree import ConfigTree
22
25
 
23
26
  defaults = config(
24
27
  coverage=False,
@@ -33,6 +36,11 @@ defaults = config(
33
36
  opts=[],
34
37
  tests=["cs", "tests"], # Strong convention @CONTACT
35
38
  test_report="pytest.xml",
39
+ playwright=config(
40
+ enabled=False,
41
+ browsers_path="{spin.data}/playwright_browsers",
42
+ browsers=["chromium"],
43
+ ),
36
44
  requires=config(
37
45
  spin=[
38
46
  "csspin_python.debugpy",
@@ -47,31 +55,49 @@ defaults = config(
47
55
  )
48
56
 
49
57
 
58
+ def _install_playwright_browsers(cfg: ConfigTree) -> None:
59
+ """Let playwright install the browsers"""
60
+ sh(
61
+ f"playwright install {' '.join(cfg.pytest.playwright.browsers)}",
62
+ env={"PLAYWRIGHT_BROWSERS_PATH": cfg.pytest.playwright.browsers_path},
63
+ )
64
+
65
+
66
+ def configure(cfg: ConfigTree) -> None:
67
+ if interpolate1(cfg.pytest.playwright.enabled).lower() == "true":
68
+ cfg.pytest.requires.python.extend(["pytest-base-url", "pytest-playwright"])
69
+
70
+
71
+ def provision(cfg: ConfigTree) -> None:
72
+ if cfg.pytest.playwright.enabled:
73
+ _install_playwright_browsers(cfg)
74
+
75
+
50
76
  @task(when="test")
51
77
  def pytest( # pylint: disable=too-many-arguments,too-many-positional-arguments
52
- cfg,
53
- instance: option(
78
+ cfg: ConfigTree,
79
+ instance: option( # type: ignore[valid-type]
54
80
  "-i", # noqa: F821
55
81
  "--instance", # noqa: F821
56
82
  default=None,
57
83
  help="Directory of the CONTACT Elements instance.", # noqa: F722
58
84
  ),
59
- coverage: option(
85
+ coverage: option( # type: ignore[valid-type]
60
86
  "-c", # noqa: F821
61
87
  "--coverage", # noqa: F821
62
88
  is_flag=True,
63
89
  help="Run the tests while collecting coverage.", # noqa: F722
64
90
  ),
65
- debug: option(
91
+ debug: option( # type: ignore[valid-type]
66
92
  "--debug", is_flag=True, help="Start debug server." # noqa: F722,F821
67
93
  ),
68
- with_test_report: option(
94
+ with_test_report: option( # type: ignore[valid-type]
69
95
  "--with-test-report", # noqa: F722
70
96
  is_flag=True,
71
97
  help="Create a test execution report.", # noqa: F722
72
98
  ),
73
- args,
74
- ):
99
+ args: Iterable[str],
100
+ ) -> None:
75
101
  """Run the 'pytest' command."""
76
102
  opts = cfg.pytest.opts
77
103
  if cfg.verbosity == Verbosity.QUIET:
@@ -85,6 +111,20 @@ def pytest( # pylint: disable=too-many-arguments,too-many-positional-arguments
85
111
  else:
86
112
  cmd = ["pytest"]
87
113
 
114
+ if cfg.pytest.playwright.enabled:
115
+ setenv(
116
+ PLAYWRIGHT_BROWSERS_PATH=cfg.pytest.playwright.browsers_path,
117
+ PACKAGE_NAME=cfg.spin.project_name,
118
+ )
119
+ for browser in cfg.pytest.playwright.browsers:
120
+ opts.extend(["--browser", browser])
121
+ # Run the browser download again, so that changes for
122
+ # cfg.pytest.playwright.browsers don't require a new provision call. If the
123
+ # browsers are already present it's more or less a noop.
124
+ _install_playwright_browsers(cfg)
125
+ if coverage or cfg.pytest.coverage:
126
+ setenv(PLAYWRIGHT_COVERAGE=1)
127
+
88
128
  if cfg.loaded.get("csspin_ce.mkinstance"):
89
129
  if not (
90
130
  inst := Path(instance or cfg.mkinstance.base.instance_location).absolute()
@@ -25,3 +25,22 @@ pytest:
25
25
  tests:
26
26
  type: list
27
27
  help: List of test files or directories to include.
28
+ playwright:
29
+ type: object
30
+ help: |
31
+ Settings necessary to also run playwright tests with the pytest
32
+ plugin.
33
+ properties:
34
+ enabled:
35
+ type: bool
36
+ help: |
37
+ Should the pytest-playwright plugin be installed and
38
+ initialized.
39
+ browsers_path:
40
+ type: path
41
+ help: Path for playwright to install the browsers.
42
+ browsers:
43
+ type: list
44
+ help: |
45
+ The browsers to install and to use for running the
46
+ playwright tests.