Skip to content

Commit

Permalink
Merge pull request #11265 from finnagin/main
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Jul 19, 2022
2 parents c9cb7f4 + 48bcb0a commit b1a01ef
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
Empty file.
11 changes: 0 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import shutil
import subprocess
import sys
import time
from contextlib import ExitStack, contextmanager
from pathlib import Path
from typing import (
Expand Down Expand Up @@ -658,16 +657,6 @@ def mock_server() -> Iterator[MockServer]:
yield test_server


@pytest.fixture
def utc() -> Iterator[None]:
# time.tzset() is not implemented on some platforms, e.g. Windows.
tzset = getattr(time, "tzset", lambda: None)
with patch.dict(os.environ, {"TZ": "UTC"}):
tzset()
yield
tzset()


@pytest.fixture
def proxy(request: pytest.FixtureRequest) -> str:
return request.config.getoption("proxy")
5 changes: 3 additions & 2 deletions tests/unit/test_base_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import time
from optparse import Values
from pathlib import Path
from typing import Callable, Iterator, List, NoReturn, Optional
Expand All @@ -15,8 +16,8 @@


@pytest.fixture
def fixed_time(utc: None) -> Iterator[None]:
with patch("time.time", lambda: 1547704837.040001):
def fixed_time() -> Iterator[None]:
with patch("time.time", lambda: 1547704837.040001 + time.timezone):
yield


Expand Down
15 changes: 7 additions & 8 deletions tests/unit/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import time
from threading import Thread
from unittest.mock import patch

Expand All @@ -22,7 +23,7 @@ def make_record(self, msg: str, level_name: str) -> logging.LogRecord:
level_number = getattr(logging, level_name)
attrs = dict(
msg=msg,
created=1547704837.040001,
created=1547704837.040001 + time.timezone,
msecs=40,
levelname=level_name,
levelno=level_number,
Expand All @@ -41,7 +42,7 @@ def make_record(self, msg: str, level_name: str) -> logging.LogRecord:
("CRITICAL", "ERROR: hello\nworld"),
],
)
def test_format(self, level_name: str, expected: str, utc: None) -> None:
def test_format(self, level_name: str, expected: str) -> None:
"""
Args:
level_name: a logging level name (e.g. "WARNING").
Expand All @@ -61,9 +62,7 @@ def test_format(self, level_name: str, expected: str, utc: None) -> None:
),
],
)
def test_format_with_timestamp(
self, level_name: str, expected: str, utc: None
) -> None:
def test_format_with_timestamp(self, level_name: str, expected: str) -> None:
record = self.make_record("hello\nworld", level_name=level_name)
f = IndentingFormatter(fmt="%(message)s", add_timestamp=True)
assert f.format(record) == expected
Expand All @@ -76,7 +75,7 @@ def test_format_with_timestamp(
("CRITICAL", "DEPRECATION: hello\nworld"),
],
)
def test_format_deprecated(self, level_name: str, expected: str, utc: None) -> None:
def test_format_deprecated(self, level_name: str, expected: str) -> None:
"""
Test that logged deprecation warnings coming from deprecated()
don't get another prefix.
Expand All @@ -88,7 +87,7 @@ def test_format_deprecated(self, level_name: str, expected: str, utc: None) -> N
f = IndentingFormatter(fmt="%(message)s")
assert f.format(record) == expected

def test_thread_safety_base(self, utc: None) -> None:
def test_thread_safety_base(self) -> None:
record = self.make_record(
"DEPRECATION: hello\nworld",
level_name="WARNING",
Expand All @@ -105,7 +104,7 @@ def thread_function() -> None:
thread.join()
assert results[0] == results[1]

def test_thread_safety_indent_log(self, utc: None) -> None:
def test_thread_safety_indent_log(self) -> None:
record = self.make_record(
"DEPRECATION: hello\nworld",
level_name="WARNING",
Expand Down

0 comments on commit b1a01ef

Please sign in to comment.