Skip to content

Commit 60ae5e0

Browse files
committed
fix some tests
1 parent f825e96 commit 60ae5e0

File tree

20 files changed

+45
-33
lines changed

20 files changed

+45
-33
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ show_missing = True
3030
skip_covered = True
3131
sort = Name
3232
exclude_lines =
33-
coverage: skip
33+
pragma: no cover
3434
\.\.\.
3535
raise NotImplementedError
3636
omit =

src/idom/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
try:
55
__version__: str = _get_distribution(__name__).version
6-
except _DistributionNotFound: # coverage: skip
6+
except _DistributionNotFound: # pragma: no cover
77
# package is not installed
88
__version__ = "0.0.0"
99

@@ -24,7 +24,7 @@
2424
import htm
2525
import pyalect
2626
import tagged
27-
except ImportError: # coverage: skip
27+
except ImportError: # pragma: no cover
2828
pass
2929
else:
3030
from . import dialect

src/idom/_option.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import os
4-
from typing import Any, Callable, Generic, TypeVar
4+
from typing import Any, Callable, Generic, TypeVar, cast
55

66
_O = TypeVar("_O")
77

@@ -14,7 +14,7 @@ def __init__(
1414
name: str,
1515
default: _O,
1616
allow_changes: bool = True,
17-
validator: Callable[[Any], _O] = lambda x: x,
17+
validator: Callable[[Any], _O] = lambda x: cast(_O, x),
1818
) -> None:
1919
self.name = name
2020
self._default = default

src/idom/client/_private.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
BACKUP_BUILD_DIR = APP_DIR / "build"
1313

1414

15-
if not IDOM_CLIENT_BUILD_DIR.get().exists():
15+
if not IDOM_CLIENT_BUILD_DIR.get().exists(): # pragma: no cover
1616
shutil.copytree(BACKUP_BUILD_DIR, IDOM_CLIENT_BUILD_DIR.get(), symlinks=True)
1717

1818

src/idom/client/manage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def build(packages_to_install: Sequence[str], clean_build: bool = False) -> None
111111

112112
not_discovered = package_names_to_install.difference(web_module_names())
113113
if not_discovered:
114-
raise RuntimeError( # coverage: skip
114+
raise RuntimeError( # pragma: no cover
115115
f"Successfuly installed {list(package_names_to_install)} but "
116116
f"failed to discover {list(not_discovered)} post-install."
117117
)
@@ -129,7 +129,7 @@ def _run_subprocess(args: List[str], cwd: Path) -> None:
129129
cmd, *args = args
130130
which_cmd = shutil.which(cmd)
131131
if which_cmd is None:
132-
raise RuntimeError( # coverage: skip
132+
raise RuntimeError( # pragma: no cover
133133
f"Failed to run command - {cmd!r} is not installed."
134134
)
135135
try:
@@ -140,7 +140,7 @@ def _run_subprocess(args: List[str], cwd: Path) -> None:
140140
stdout=subprocess.PIPE,
141141
stderr=subprocess.PIPE,
142142
)
143-
except subprocess.CalledProcessError as error: # coverage: skip
143+
except subprocess.CalledProcessError as error: # pragma: no cover
144144
raise subprocess.SubprocessError(error.stderr.decode()) from error
145145
return None
146146

src/idom/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
IDOM_CLIENT_WEB_MODULE_BASE_URL = _option.Option(
2121
"IDOM_CLIENT_WEB_MODULE_BASE_URL",
2222
default=".",
23-
validator=lambda x: x.rstrip("/"),
23+
validator=lambda x: str(x).rstrip("/"),
2424
)
2525
"""The base URL where all user-installed web modules reside"""

src/idom/core/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from functools import wraps
44
from typing import TYPE_CHECKING, Any, Callable, Dict, Tuple, Union
55

6-
if TYPE_CHECKING: # coverage: skip
6+
if TYPE_CHECKING: # pragma: no cover
77
from .vdom import VdomDict # noqa
88

99

src/idom/core/events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __iter__(self) -> Iterator[str]:
134134
def __getitem__(self, key: str) -> "EventHandler":
135135
return self._handlers[key]
136136

137-
def __repr__(self) -> str: # coverage: skip
137+
def __repr__(self) -> str: # pragma: no cover
138138
return repr(self._handlers)
139139

140140

@@ -229,5 +229,5 @@ def __contains__(self, function: Any) -> bool:
229229
else:
230230
return function in self._func_handlers
231231

232-
def __repr__(self) -> str: # coverage: skip
232+
def __repr__(self) -> str: # pragma: no cover
233233
return f"{type(self).__name__}({self.serialize()})"

src/idom/core/layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Layout(HasAsyncResources):
6767

6868
__slots__ = ["root", "_event_handlers"]
6969

70-
if not hasattr(abc.ABC, "__weakref__"): # coverage: skip
70+
if not hasattr(abc.ABC, "__weakref__"): # pragma: no cover
7171
__slots__.append("__weakref__")
7272

7373
def __init__(self, root: "AbstractComponent") -> None:

src/idom/core/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
overload,
1515
)
1616

17-
if sys.version_info >= (3, 7): # coverage: skip
17+
if sys.version_info >= (3, 7): # pragma: no cover
1818
from contextlib import AsyncExitStack, asynccontextmanager # noqa
19-
else: # coverage: skip
19+
else: # pragma: no cover
2020
from async_exit_stack import AsyncExitStack
2121
from async_generator import asynccontextmanager
2222

src/idom/server/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def run(self, host: str, port: int, *args: Any, **kwargs: Any) -> None:
4444
if self._app is None:
4545
app = self._default_application(self._config)
4646
self.register(app)
47-
else: # coverage: skip
47+
else: # pragma: no cover
4848
app = self._app
49-
if not self._daemonized: # coverage: skip
49+
if not self._daemonized: # pragma: no cover
5050
return self._run_application(self._config, app, host, port, args, kwargs)
5151
else:
5252
return self._run_application_in_thread(
@@ -76,7 +76,7 @@ def register(self: _Self, app: Optional[_App]) -> _Self:
7676
def wait_until_server_start(self, timeout: float = 3.0) -> None:
7777
"""Block until the underlying application has started"""
7878
if not self._server_did_start.wait(timeout=timeout):
79-
raise RuntimeError( # coverage: skip
79+
raise RuntimeError( # pragma: no cover
8080
f"Server did not start within {timeout} seconds"
8181
)
8282

src/idom/server/flask.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FlaskRenderServer(AbstractRenderServer[Flask, Config]):
4545
def stop(self, timeout: Optional[float] = None) -> None:
4646
try:
4747
server = self._wsgi_server
48-
except AttributeError: # coverage: skip
48+
except AttributeError: # pragma: no cover
4949
raise RuntimeError(
5050
f"Application is not running or was not started by {self}"
5151
)
@@ -72,7 +72,7 @@ def _setup_application(self, config: Config, app: Flask) -> None:
7272
self._setup_blueprint_routes(config, bp)
7373

7474
cors_config = config["cors"]
75-
if cors_config: # coverage: skip
75+
if cors_config: # pragma: no cover
7676
cors_params = cors_config if isinstance(cors_config, dict) else {}
7777
CORS(bp, **cors_params)
7878

@@ -164,7 +164,7 @@ def _generic_run_application(
164164
**kwargs: Any,
165165
) -> None:
166166
if debug:
167-
logging.basicConfig(level=logging.DEBUG) # coverage: skip
167+
logging.basicConfig(level=logging.DEBUG) # pragma: no cover
168168
logger.info(f"Running at http://{host}:{port}")
169169
self._wsgi_server = _StartCallbackWSGIServer(
170170
self._server_did_start.set,
@@ -274,7 +274,7 @@ def update_environ(self) -> None:
274274
"""
275275
super().update_environ()
276276
# BUG: for some reason coverage doesn't seem to think this line is covered
277-
self._before_first_request_callback() # coverage: skip
277+
self._before_first_request_callback() # pragma: no cover
278278

279279

280280
def _join_url_paths(*args: str) -> str:

src/idom/server/prefab.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ def run(
4646
The server instance. This isn't really useful unless the server is spawned
4747
as a daemon. Otherwise this function blocks until the server has stopped.
4848
"""
49-
if port is None: # coverage: skip
49+
if server_type is None: # pragma: no cover
50+
raise ValueError("No default server available.")
51+
if port is None: # pragma: no cover
5052
port = find_available_port(host)
5153

5254
logger.info(f"Using {server_type.__module__}.{server_type.__name__}")
5355

5456
server = server_type(component, server_config)
5557

56-
if app is not None: # coverage: skip
58+
if app is not None: # pragma: no cover
5759
server.register(app)
5860

5961
run_server = server.run if not daemon else server.daemon

src/idom/server/sanic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async def _activate_dispatcher(
195195

196196
async def _deactivate_dispatcher(
197197
self, app: Sanic, loop: asyncio.AbstractEventLoop
198-
) -> None: # coverage: skip
198+
) -> None: # pragma: no cover
199199
# this doesn't seem to get triggered during testing for some reason
200200
await self._dispatcher.stop()
201201

src/idom/server/tornado.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TornadoRenderServer(AbstractRenderServer[Application, Config]):
3636
def stop(self) -> None:
3737
try:
3838
loop = self._loop
39-
except AttributeError: # coverage: skip
39+
except AttributeError: # pragma: no cover
4040
raise RuntimeError(
4141
f"Application is not running or was not started by {self}"
4242
)

src/idom/server/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ def find_builtin_server_type(type_name: str) -> Type[Any]:
1212
for name in supported_packages:
1313
try:
1414
import_module(name)
15-
except ImportError: # coverage: skip
15+
except ImportError: # pragma: no cover
1616
continue
1717
else:
1818
builtin_module = import_module(f"idom.server.{name}")
1919
installed_builtins.append(builtin_module.__name__)
2020
try:
2121
return getattr(builtin_module, type_name) # type: ignore
22-
except AttributeError: # coverage: skip
22+
except AttributeError: # pragma: no cover
2323
pass
24-
else: # coverage: skip
24+
else: # pragma: no cover
2525
if not installed_builtins:
2626
raise RuntimeError(
2727
f"Found none of the following builtin server implementations {supported_packages}"

src/idom/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def assert_logged_exception(
105105
error = record.exc_info[1]
106106
if isinstance(error, error_type) and re_pattern.search(str(error)):
107107
break
108-
else: # coverage: skip
108+
else: # pragma: no cover
109109
assert False, f"did not raise {error_type} matching {error_pattern!r}"
110110
finally:
111111
if clear_after:

tests/test_client/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import idom
44

55

6+
@pytest.fixture
7+
def htm():
8+
return idom.install("htm@3.0.4")
9+
10+
611
@pytest.fixture
712
def victory():
813
return idom.install("victory@35.4.0")

tests/test_client/test_manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_web_module_path_must_exist():
2323

2424
def test_web_module_url(victory):
2525
assert web_module_exists("victory")
26-
assert web_module_url("victory") == "./_snowpack/pkg/victory.js"
26+
assert web_module_url("victory") == "./victory.js"
2727

2828

2929
def test_web_module_exports(victory):

tests/test_client/test_module.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ def test_module_from_url():
4343
assert jquery.url == url
4444

4545

46-
def test_module_from_source(driver, driver_wait, display):
46+
def test_module_from_source(
47+
driver,
48+
driver_wait,
49+
display,
50+
htm, # we need this in order to run the test js module
51+
):
4752
test_module = Module("test-module", source_file=HERE / "test_js_module.js")
4853

4954
response_data = idom.Ref(None)

0 commit comments

Comments
 (0)