Skip to content

Commit

Permalink
🚧 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Nov 28, 2024
1 parent e29c31f commit d8e8935
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
10 changes: 0 additions & 10 deletions wake/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,6 @@ def run_init(
end = time.perf_counter()
console.log(f"[green]Generated pytypes in [bold green]{end - start:.2f} s[/]")

if "wake_remote" not in config.api_keys:
import uuid
# import toml
wake_remote_key = str(uuid.uuid4())
config.update({"api_keys": {"wake_remote": wake_remote_key}}, [])
# global config path already made when WakeConfig was created
wake_remote_file = config.global_config_path.parent / "wake_remote.txt"
with wake_remote_file.open("w") as f:
f.write(config.api_keys["wake_remote"])

if not config.local_config_path.exists() or force:
write_config(config)

Expand Down
27 changes: 25 additions & 2 deletions wake/cli/qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@


@click.command(name="qr")
def run_qr() -> None:
@click.option(
"--force",
"-f",
is_flag=True,
default=False,
help="Force generate new QR code.",
)
@click.pass_context
def run_qr(context: click.Context, force: bool) -> None:
import qrcode

from wake.config import WakeConfig

config = WakeConfig(local_config_path=context.obj.get("local_config_path", None))
config.load_configs()

if "wake_remote" not in config.api_keys or force:
import uuid

wake_remote_key = str(uuid.uuid4())
config.update({"api_keys": {"wake_remote": wake_remote_key}}, [])
# global config path already made when WakeConfig was created
wake_remote_file = config.global_config_path.parent / "wake_remote.txt"
with wake_remote_file.open("w") as f:
f.write(config.api_keys["wake_remote"])

qr = qrcode.QRCode()
qr.add_data("Some text")
qr.add_data(config.api_keys["wake_remote"])
qr.print_ascii()
10 changes: 9 additions & 1 deletion wake/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ def shell_complete(
default="duplicated",
help="Distribution of test cases to processes.",
)
@click.option(
"--remote",
is_flag=True,
default=False,
help="Notifies remote about test run.",
)
@click.option(
"-v",
"--verbosity",
Expand All @@ -235,6 +241,7 @@ def run_test(
seeds: Tuple[str],
attach_first: bool,
dist: str,
remote: bool,
verbosity: int,
paths_or_pytest_args: Tuple[str, ...],
) -> None:
Expand Down Expand Up @@ -327,6 +334,7 @@ def run_test(
attach_first,
debug,
dist,
remote,
pytest_args,
)
],
Expand All @@ -339,7 +347,7 @@ def run_test(
pytest.main(
pytest_args,
plugins=[
PytestWakePluginSingle(config, debug, coverage, random_seeds)
PytestWakePluginSingle(config, debug, coverage, random_seeds, remote)
],
)
)
24 changes: 20 additions & 4 deletions wake/testing/pytest_plugin_multiprocess_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import pickle
import shutil
import signal
import logging
from contextlib import nullcontext
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union
from uuid import uuid4

import pytest
import rich.progress
Expand All @@ -21,6 +23,9 @@
export_merged_ide_coverage,
write_coverage,
)
from wake.core import get_logger

logger = get_logger(__name__)

from .pytest_plugin_multiprocess import PytestWakePluginMultiprocess

Expand All @@ -44,6 +49,7 @@ class PytestWakePluginMultiprocessServer:
]

_firebase_token: Optional[str]
_session_id: str

def __init__(
self,
Expand All @@ -54,6 +60,7 @@ def __init__(
attach_first: bool,
debug: bool,
dist: str,
remote: bool,
pytest_args: List[str],
):
self._config = config
Expand All @@ -67,8 +74,10 @@ def __init__(
self._pytest_args = pytest_args
self._exported_coverages = {i: {} for i in range(self._proc_count)}

if config.wake_remote.uuid is not None:
cred = credentials.Certificate(config.global_data_path / "fuzz-firebase-adminsdk.json")
self._session_id = str(uuid4())

if remote and config.api_keys.get("wake_remote") is not None:
cred = credentials.Certificate(config.global_config_path.parent / "fuzz-firebase-adminsdk.json")
initialize_app(
cred,
{
Expand All @@ -77,7 +86,14 @@ def __init__(
)

x = db.reference("/")
self._firebase_token = x.child("tokens").child(config.wake_remote.uuid).get()
try:
self._firebase_token = x.child("tokens").child(config.api_keys["wake_remote"]).get()
if self._firebase_token is None:
logger.warning("No Firebase token found for remote server.")
except Exception as e:
logger.error(f"Failed to get Firebase token for remote server: {e}")
else:
self._firebase_token = None

def pytest_sessionstart(self, session: pytest.Session):
if self._coverage != 0:
Expand Down Expand Up @@ -249,7 +265,7 @@ def pytest_runtestloop(self, session: pytest.Session):
message = messaging.Message(
token=self._firebase_token,
notification=messaging.Notification(
title=f"Exception {}",
title=f"Exception {exception_info[0]}",
body=f"Process #{index}",
)
)
Expand Down

0 comments on commit d8e8935

Please sign in to comment.