@pyscript/core 0.1.22 → 0.2.1

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.
Files changed (41) hide show
  1. package/dist/core.css +1 -1
  2. package/dist/core.js +2 -2
  3. package/dist/core.js.map +1 -1
  4. package/dist/error-e4fe78fd.js +2 -0
  5. package/dist/error-e4fe78fd.js.map +1 -0
  6. package/package.json +2 -2
  7. package/src/core.css +3 -1
  8. package/src/core.js +170 -161
  9. package/src/plugins/error.js +2 -2
  10. package/src/stdlib/pyscript/__init__.py +10 -1
  11. package/src/stdlib/pyscript/display.py +7 -0
  12. package/src/stdlib/pyscript/util.py +3 -4
  13. package/src/stdlib/pyscript.js +3 -3
  14. package/dist/error-87e0706c.js +0 -2
  15. package/dist/error-87e0706c.js.map +0 -1
  16. package/tests/integration/__init__.py +0 -0
  17. package/tests/integration/conftest.py +0 -184
  18. package/tests/integration/support.py +0 -1038
  19. package/tests/integration/test_00_support.py +0 -495
  20. package/tests/integration/test_01_basic.py +0 -353
  21. package/tests/integration/test_02_display.py +0 -452
  22. package/tests/integration/test_03_element.py +0 -303
  23. package/tests/integration/test_assets/line_plot.png +0 -0
  24. package/tests/integration/test_assets/tripcolor.png +0 -0
  25. package/tests/integration/test_async.py +0 -197
  26. package/tests/integration/test_event_handling.py +0 -193
  27. package/tests/integration/test_importmap.py +0 -66
  28. package/tests/integration/test_interpreter.py +0 -98
  29. package/tests/integration/test_plugins.py +0 -419
  30. package/tests/integration/test_py_config.py +0 -294
  31. package/tests/integration/test_py_repl.py +0 -663
  32. package/tests/integration/test_py_terminal.py +0 -270
  33. package/tests/integration/test_runtime_attributes.py +0 -64
  34. package/tests/integration/test_script_type.py +0 -121
  35. package/tests/integration/test_shadow_root.py +0 -33
  36. package/tests/integration/test_splashscreen.py +0 -124
  37. package/tests/integration/test_stdio_handling.py +0 -370
  38. package/tests/integration/test_style.py +0 -47
  39. package/tests/integration/test_warnings_and_banners.py +0 -32
  40. package/tests/integration/test_zz_examples.py +0 -419
  41. package/tests/integration/test_zzz_docs_snippets.py +0 -305
@@ -1,184 +0,0 @@
1
- import shutil
2
- import threading
3
- from http.server import HTTPServer as SuperHTTPServer
4
- from http.server import SimpleHTTPRequestHandler
5
-
6
- import pytest
7
-
8
- from .support import Logger
9
-
10
-
11
- def pytest_cmdline_main(config):
12
- """
13
- If we pass --clear-http-cache, we don't enter the main pytest logic, but
14
- use our custom main instead
15
- """
16
-
17
- def mymain(config, session):
18
- print()
19
- print("-" * 20, "SmartRouter HTTP cache", "-" * 20)
20
- # unfortunately pytest-cache doesn't offer a public API to selectively
21
- # clear the cache, so we need to peek its internal. The good news is
22
- # that pytest-cache is very old, stable and robust, so it's likely
23
- # that this won't break anytime soon.
24
- cache = config.cache
25
- base = cache._cachedir.joinpath(cache._CACHE_PREFIX_VALUES, "pyscript")
26
- if not base.exists():
27
- print("No cache found, nothing to do")
28
- return 0
29
- #
30
- print("Requests found in the cache:")
31
- for f in base.rglob("*"):
32
- if f.is_file():
33
- # requests are saved in dirs named pyscript/http:/foo/bar, let's turn
34
- # them into a proper url
35
- url = str(f.relative_to(base))
36
- url = url.replace(":/", "://")
37
- print(" ", url)
38
- shutil.rmtree(base)
39
- print("Cache cleared")
40
- return 0
41
-
42
- if config.option.clear_http_cache:
43
- from _pytest.main import wrap_session
44
-
45
- return wrap_session(config, mymain)
46
- return None
47
-
48
-
49
- def pytest_configure(config):
50
- """
51
- THIS IS A WORKAROUND FOR A pytest QUIRK!
52
-
53
- At the moment of writing this conftest defines two new options, --dev and
54
- --no-fake-server, but because of how pytest works, they are available only
55
- if this is the "root conftest" for the test session.
56
-
57
- This means that if you are in the pyscriptjs directory:
58
-
59
- $ py.test # does NOT work
60
- $ py.test tests/integration/ # works
61
-
62
- This happens because there is also test py-unit directory, so in the first
63
- case the "root conftest" would be tests/conftest.py (which doesn't exist)
64
- instead of this.
65
-
66
- There are various workarounds, but for now we can just detect it and
67
- inform the user.
68
-
69
- Related StackOverflow answer: https://stackoverflow.com/a/51733980
70
- """
71
- if not hasattr(config.option, "dev"):
72
- msg = """
73
- Running a bare "pytest" command from the pyscriptjs directory
74
- is not supported. Please use one of the following commands:
75
- - pytest tests/integration
76
- - pytest tests/py-unit
77
- - pytest tests/*
78
- - cd tests/integration; pytest
79
- """
80
- pytest.fail(msg)
81
- else:
82
- if config.option.dev:
83
- config.option.headed = True
84
- config.option.no_fake_server = True
85
-
86
-
87
- @pytest.fixture(scope="session")
88
- def logger():
89
- return Logger()
90
-
91
-
92
- def pytest_addoption(parser):
93
- parser.addoption(
94
- "--no-fake-server",
95
- action="store_true",
96
- help="Use a real HTTP server instead of http://fakeserver",
97
- )
98
- parser.addoption(
99
- "--dev",
100
- action="store_true",
101
- help="Automatically open a devtools panel. Implies --headed and --no-fake-server",
102
- )
103
- parser.addoption(
104
- "--clear-http-cache",
105
- action="store_true",
106
- help="Clear the cache of HTTP requests for SmartRouter",
107
- )
108
-
109
-
110
- @pytest.fixture(scope="session")
111
- def browser_type_launch_args(request):
112
- """
113
- Override the browser_type_launch_args defined by pytest-playwright to
114
- support --devtools.
115
-
116
- NOTE: this has been tested with pytest-playwright==0.3.0. It might break
117
- with newer versions of it.
118
- """
119
- # this calls the "original" fixture defined by pytest_playwright.py
120
- launch_options = request.getfixturevalue("browser_type_launch_args")
121
- if request.config.option.dev:
122
- launch_options["devtools"] = True
123
- return launch_options
124
-
125
-
126
- class DevServer(SuperHTTPServer):
127
- """
128
- Class for wrapper to run SimpleHTTPServer on Thread.
129
- Ctrl +Only Thread remains dead when terminated with C.
130
- Keyboard Interrupt passes.
131
- """
132
-
133
- def __init__(self, base_url, *args, **kwargs):
134
- self.base_url = base_url
135
- super().__init__(*args, **kwargs)
136
-
137
- def run(self):
138
- try:
139
- self.serve_forever()
140
- except KeyboardInterrupt:
141
- pass
142
- finally:
143
- self.server_close()
144
-
145
-
146
- @pytest.fixture(scope="session")
147
- def dev_server(logger):
148
- class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
149
- enable_cors_headers = True
150
-
151
- @classmethod
152
- def my_headers(cls):
153
- if cls.enable_cors_headers:
154
- return {
155
- "Cross-Origin-Embedder-Policy": "require-corp",
156
- "Cross-Origin-Opener-Policy": "same-origin",
157
- }
158
- return {}
159
-
160
- def end_headers(self):
161
- self.send_my_headers()
162
- SimpleHTTPRequestHandler.end_headers(self)
163
-
164
- def send_my_headers(self):
165
- for k, v in self.my_headers().items():
166
- self.send_header(k, v)
167
-
168
- def log_message(self, fmt, *args):
169
- logger.log("http_server", fmt % args, color="blue")
170
-
171
- host, port = "localhost", 8080
172
- base_url = f"http://{host}:{port}"
173
-
174
- # serve_Run forever under thread
175
- server = DevServer(base_url, (host, port), MyHTTPRequestHandler)
176
-
177
- thread = threading.Thread(None, server.run)
178
- thread.start()
179
-
180
- yield server # Transition to test here
181
-
182
- # End thread
183
- server.shutdown()
184
- thread.join()