Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: python3 .github/scripts/poetry_install.py --version 2.2.1

- name: Install dependencies
run: poetry install --no-root
run: poetry install

- name: Run formatters in check mode
run: poetry run poe checks_codestyle
3 changes: 2 additions & 1 deletion goth/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main entry point to `goth`."""

import argparse
import asyncio
from datetime import datetime, timezone
Expand All @@ -20,7 +21,7 @@
def make_logs_dir(base_dir: Path) -> Path:
"""Create a unique subdirectory for this test run."""

date_str = datetime.now(tz=timezone.utc).strftime("%Y-%m-%d_%H-%M-%S")
date_str = datetime.now(timezone.utc).strftime("%Y-%m-%d_%H-%M-%S")
log_dir = base_dir / f"goth_{date_str}"
log_dir.mkdir(parents=True)

Expand Down
1 change: 1 addition & 0 deletions goth/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
in the proxy container. If you rename any of them here then make sure to also
apply the same renaming in `nginx.conf`.
"""

from string import Template
from typing import Dict, Mapping, Optional

Expand Down
1 change: 1 addition & 0 deletions goth/assertions/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common assertions related to API calls."""

from typing import Set

from goth.api_monitor.api_events import (
Expand Down
1 change: 1 addition & 0 deletions goth/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines a class representing `goth` configuration."""

from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Type, Union
from dpath import MergeType
Expand Down
7 changes: 4 additions & 3 deletions goth/interactive.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
"""Interactive runner for `goth` network."""

import asyncio
import logging
from pathlib import Path
import tempfile
from typing import Dict, Optional

from goth.configuration import Configuration
from goth.runner import Runner
from goth.runner.download import ASSET_CACHE_DIR
from goth.runner.probe import ProviderProbe, RequestorProbe


logger = logging.getLogger(__name__)

env_file: Path = Path(tempfile.gettempdir()) / "goth_interactive.env"
env_file: Path = ASSET_CACHE_DIR / "goth_interactive.env"


def _write_env_file(env: Dict[str, str]) -> None:
ASSET_CACHE_DIR.mkdir(parents=True, exist_ok=True)
with env_file.open("w") as f:
for key, val in env.items():
f.write(f"export {key}={val}\n")
Expand Down
1 change: 1 addition & 0 deletions goth/payment_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All possible payment-related configuration, in one place."""

from dataclasses import dataclass, field
from typing import Dict

Expand Down
1 change: 1 addition & 0 deletions goth/project.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module with information on the project itself, e.g. project root directory."""

from pathlib import Path

import goth
Expand Down
4 changes: 1 addition & 3 deletions goth/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
from contextlib import asynccontextmanager, AsyncExitStack
from datetime import datetime, timezone
from itertools import chain
import logging
import os
Expand Down Expand Up @@ -113,8 +112,7 @@ def __init__(
):
# Set up the logging directory for this runner
self.test_name = test_name or self._current_pytest_test_name() or ""
date_str = datetime.now(tz=timezone.utc).strftime("%Y-%m-%d_%H-%M-%S")
self.log_dir = base_log_dir / self.test_name / date_str
self.log_dir = base_log_dir / self.test_name
self.log_dir.mkdir(parents=True, exist_ok=True)

self.api_assertions_module = api_assertions_module
Expand Down
4 changes: 2 additions & 2 deletions goth/runner/container/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Classes and utilties to manage docker Containers."""

from dataclasses import dataclass, field
from datetime import datetime
from datetime import datetime, timezone
from enum import Enum
from pathlib import Path
from typing import Callable, Dict, List, Optional
Expand Down Expand Up @@ -205,7 +205,7 @@ def _restart(self):
# using naive datetime object as `since` argument deliberately
# see: https://github.com/docker/docker-py/issues/2712
self.logs.update_stream(
self._container.logs(stream=True, follow=True, since=datetime.utcnow())
self._container.logs(stream=True, follow=True, since=datetime.now(timezone.utc))
)

def _update_state(self, *_args, **_kwargs):
Expand Down
26 changes: 14 additions & 12 deletions goth/runner/container/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
from pathlib import Path
import shutil
from tempfile import TemporaryDirectory
from typing import Callable, List, Optional, Dict

from goth.project import PROJECT_ROOT
Expand All @@ -14,6 +13,7 @@
ArtifactDownloader,
ReleaseDownloader,
ENV_API_TOKEN,
ASSET_CACHE_DIR,
)
from goth.runner.process import run_command

Expand Down Expand Up @@ -87,18 +87,20 @@ async def _build_docker_image(
) -> None:
"""Set up a temporary build directory and issue `docker build` command there."""

with TemporaryDirectory() as temp_path:
build_dir = Path(temp_path)
setup_context(build_dir)
rnd_str = os.urandom(4).hex()
build_dir = ASSET_CACHE_DIR / "docker_build" / rnd_str
build_dir.mkdir(parents=True)

logger.info(
"Building %s Docker image. dockerfile=%s, build dir=%s",
image_name,
dockerfile,
build_dir,
)
command = ["docker", "build", "-t", image_name, str(build_dir)]
await run_command(command)
setup_context(build_dir)

logger.info(
"Building %s Docker image. dockerfile=%s, build dir=%s",
image_name,
dockerfile,
build_dir,
)
command = ["docker", "build", "-t", image_name, str(build_dir)]
await run_command(command)


async def build_proxy_image(docker_dir: Path) -> None:
Expand Down
10 changes: 8 additions & 2 deletions goth/runner/container/compose.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Module responsible for parsing the docker-compose.yml used in the tests."""

import contextlib
from dataclasses import dataclass
from datetime import datetime
from datetime import datetime, timezone
import logging
import os
from pathlib import Path
Expand Down Expand Up @@ -260,7 +261,12 @@ def _start_log_monitors(self, log_dir: Path) -> None:
container = containers[0]

monitor.start(
container.logs(follow=True, since=datetime.utcnow(), stream=True, timestamps=True)
container.logs(
follow=True,
since=datetime.now(timezone.utc),
stream=True,
timestamps=True,
)
)
self._log_monitors[service_name] = monitor

Expand Down
1 change: 1 addition & 0 deletions goth/runner/container/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities related to Docker containers."""

from pathlib import Path
from typing import Dict, List, Tuple

Expand Down
3 changes: 2 additions & 1 deletion goth/runner/download/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Package related to downloading assets necessary for building yagna images."""

import time
from abc import ABC
import logging
Expand All @@ -18,7 +19,7 @@
)
logger = logging.getLogger(__name__)

ASSET_CACHE_DIR = Path(tempfile.gettempdir()) / "goth_asset_cache"
ASSET_CACHE_DIR = Path("cache")

ENV_API_TOKEN = "GITHUB_TOKEN"
ENV_YAGNA_BRANCH = "YAGNA_BRANCH"
Expand Down
4 changes: 2 additions & 2 deletions goth/runner/log.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Log utilities for the runner."""

import contextlib
import datetime
import os
from dataclasses import dataclass
import logging
import logging.config
from datetime import datetime, timezone
from pathlib import Path
import tempfile
import time
Expand Down Expand Up @@ -154,7 +154,7 @@ def configure_logging_for_test(test_log_dir: Path) -> None:
proxy_handler.setFormatter(formatter)
pyl_proxy_logger.addHandler(proxy_handler)
pyl_proxy_logger.info(
"Proxy log started: {}".format(datetime.datetime.utcnow().isoformat())
"Proxy log started: {}".format(datetime.now(timezone.utc).isoformat())
)
yield

Expand Down
1 change: 1 addition & 0 deletions goth/runner/probe/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for agent components to be used with `Probe` objects."""

import abc
import logging
from typing import Optional, TYPE_CHECKING
Expand Down
2 changes: 1 addition & 1 deletion goth/runner/probe/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def counter_proposal(
async def create_agreement(self: ProbeProtocol, proposal: Proposal) -> str:
"""Call create_agreement on the market api."""

valid_to = str(datetime.utcnow() + timedelta(days=1)) + "Z"
valid_to = (datetime.now(timezone.utc) + timedelta(days=1)).isoformat()
logger.debug(
"Creating agreement, proposal_id=%s, valid_to=%s",
proposal.proposal_id,
Expand Down
1 change: 1 addition & 0 deletions goth/runner/probe/rest_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module containing classes related to the yagna REST API client."""

import dataclasses
import logging
from typing import TypeVar, TYPE_CHECKING
Expand Down
1 change: 1 addition & 0 deletions goth/runner/proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A class for starting an embedded instance of mitmproxy."""

import contextlib
import logging
from typing import AsyncIterator, Mapping, Optional
Expand Down
1 change: 1 addition & 0 deletions goth/runner/step.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A minimal runner implementation."""

import asyncio
import functools
import logging
Expand Down
46 changes: 29 additions & 17 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ya-tmp-pyapi = "=0.7.0"
ghapi = "^1.0"

[tool.poetry.group.dev.dependencies]
black = "^22.1"
black = "^24.10.0"
flake8 = "^7.0"
flake8-docstrings = "^1.7"
flake8-pyproject = "^1.2"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def log_dir() -> Path:
"""Return path to dir where goth test session logs should be placed."""
base_dir = Path("/", "tmp", "goth-tests")
date_str = datetime.now(tz=timezone.utc).strftime("%Y-%m-%d_%H-%M-%S")
date_str = datetime.now(timezone.utc).strftime("%Y-%m-%d_%H-%M-%S")
log_dir = base_dir / f"goth_{date_str}"
log_dir.mkdir(parents=True)
configure_logging(log_dir)
Expand Down
1 change: 1 addition & 0 deletions test/integration/test_payment_platform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test if "payment_config" in `goth-config.yml` works as expected."""

from pathlib import Path
import pytest

Expand Down
1 change: 1 addition & 0 deletions test/integration/test_use_proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Integration test for agent-daemon communication through MITM proxy."""

import asyncio
from functools import partial
from pathlib import Path
Expand Down
9 changes: 3 additions & 6 deletions test/unit/assertions/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,14 @@ async def toplevel(_stream):
async def test_assertion_names():
"""Test if assertion names are constructed correctly."""

async def inner(_stream):
...
async def inner(_stream): ...

def make_assertion(_arg):
async def innermost(_stream):
...
async def innermost(_stream): ...

return innermost

async def parametrized(x, y, _stream):
...
async def parametrized(x, y, _stream): ...

a1 = Assertion(toplevel)
assert a1.name == f"{__name__}.toplevel"
Expand Down
1 change: 1 addition & 0 deletions test/unit/assertions/test_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the `assertions.monitor`."""

import asyncio

import pytest
Expand Down
1 change: 1 addition & 0 deletions test/unit/configuration/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for `goth.configuration` module."""

from pathlib import Path

import pytest
Expand Down
Loading