Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests in not utc tz #2

Closed
wants to merge 17 commits into from
103 changes: 40 additions & 63 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
schedule:
- cron: 0 0 * * MON # Run every Monday at 00:00 UTC

env:
# The "FORCE_COLOR" variable, when set to 1,
# tells Nox to colorize itself.
FORCE_COLOR: "1"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
Expand Down Expand Up @@ -92,8 +97,8 @@ jobs:
- run: nox -s vendoring
- run: git diff --exit-code

tests-unix:
name: tests / ${{ matrix.python }} / ${{ matrix.os }}
tests:
name: tests / ${{ matrix.python }} / ${{ matrix.os }} / ${{ matrix.group }}
runs-on: ${{ matrix.os }}-latest

needs: [pre-commit, packaging, determine-changes]
Expand All @@ -104,75 +109,54 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [Ubuntu, MacOS]
os: [Ubuntu, MacOS, Windows]
python:
- 3.7
- 3.8
- 3.9
- "3.7"
- "3.8"
- "3.9"
- "3.10"
group:
- "All"
exclude:
# Since Windows tests are expensively slow exclude some:
- os: "Windows"
group: "All"
include:
- os: "Windows"
group: "Unit & Integration 1"
python: "3.7"
- os: "Windows"
group: "Integration 2"
python: "3.7"
- os: "Windows"
group: "Unit & Integration 1"
python: "3.10"
- os: "Windows"
group: "Integration 2"
python: "3.10"

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install Ubuntu dependencies
- name: Ubuntu - Install dependencies
if: matrix.os == 'Ubuntu'
run: sudo apt-get install bzr

- name: Install MacOS dependencies
- name: MacOS - Install dependencies
if: matrix.os == 'MacOS'
run: brew install bzr

- run: pip install nox 'virtualenv<20'

# Main check
- name: Run unit tests
run: >-
nox -s test-${{ matrix.python }} --
-m unit
--verbose --numprocesses auto --showlocals
- name: Run integration tests
run: >-
nox -s test-${{ matrix.python }} --
-m integration
--verbose --numprocesses auto --showlocals
--durations=5

tests-windows:
name: tests / ${{ matrix.python }} / ${{ matrix.os }} / ${{ matrix.group }}
runs-on: ${{ matrix.os }}-latest

needs: [pre-commit, packaging, determine-changes]
if: >-
needs.determine-changes.outputs.tests == 'true' ||
github.event_name != 'pull_request'

strategy:
fail-fast: true
matrix:
os: [Windows]
python:
- 3.7
# Commented out, since Windows tests are expensively slow.
# - 3.8
# - 3.9
- "3.10"
group: [1, 2]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

# We use a RAMDisk on Windows, since filesystem IO is a big slowdown
# for our tests.
- name: Create a RAMDisk
- name: Windows - Create a RAMDisk
if: matrix.os == 'Windows'
run: ./tools/ci/New-RAMDisk.ps1 -Drive R -Size 1GB

- name: Setup RAMDisk permissions
- name: Windows - Setup RAMDisk permissions and environment
if: matrix.os == 'Windows'
run: |
mkdir R:\Temp
$acl = Get-Acl "R:\Temp"
Expand All @@ -181,35 +165,28 @@ jobs:
)
$acl.AddAccessRule($rule)
Set-Acl "R:\Temp" $acl
echo "TEMP=R:\Temp" >> $env:GITHUB_ENV

- run: pip install nox 'virtualenv<20'
env:
TEMP: "R:\\Temp"

# Main check
- name: Run unit tests
if: matrix.group == 1
if: matrix.group == 'Unit & Integration 1' || matrix.group == 'All'
run: >-
nox -s test-${{ matrix.python }} --
-m unit
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"

- name: Run integration tests (group 1)
if: matrix.group == 1
if: matrix.group == 'Unit & Integration 1' || matrix.group == 'All'
run: >-
nox -s test-${{ matrix.python }} --
-m integration -k "not test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"

- name: Run integration tests (group 2)
if: matrix.group == 2
if: matrix.group == 'Integration 2' || matrix.group == 'All'
run: >-
nox -s test-${{ matrix.python }} --
-m integration -k "test_install"
--verbose --numprocesses auto --showlocals
env:
TEMP: "R:\\Temp"
Empty file added news/10816 .trivial.rst
Empty file.
14 changes: 10 additions & 4 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
from datetime import datetime
from optparse import Values
from typing import Callable, Iterator, List, NoReturn, Optional
from unittest.mock import Mock, patch
Expand All @@ -13,10 +14,15 @@
from pip._internal.utils.temp_dir import TempDirectory
from tests.lib.path import Path

FIXED_TIME_VALUE = 1547704837.040001
FIXED_TIME_FORMAT = datetime.fromtimestamp(FIXED_TIME_VALUE).strftime(
"%Y-%m-%dT%H:%M:%S,%f"
)[:-3]


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


Expand Down Expand Up @@ -109,7 +115,7 @@ def test_log_command_success(fixed_time: None, tmpdir: Path) -> None:
log_path = tmpdir.joinpath("log")
cmd.main(["fake", "--log", log_path])
with open(log_path) as f:
assert f.read().rstrip() == "2019-01-17T06:00:37,040 fake"
assert f.read().rstrip() == f"{FIXED_TIME_FORMAT} fake"


def test_log_command_error(fixed_time: None, tmpdir: Path) -> None:
Expand All @@ -118,7 +124,7 @@ def test_log_command_error(fixed_time: None, tmpdir: Path) -> None:
log_path = tmpdir.joinpath("log")
cmd.main(["fake", "--log", log_path])
with open(log_path) as f:
assert f.read().startswith("2019-01-17T06:00:37,040 fake")
assert f.read().startswith(f"{FIXED_TIME_FORMAT} fake")


def test_log_file_command_error(fixed_time: None, tmpdir: Path) -> None:
Expand All @@ -127,7 +133,7 @@ def test_log_file_command_error(fixed_time: None, tmpdir: Path) -> None:
log_file_path = tmpdir.joinpath("log_file")
cmd.main(["fake", "--log-file", log_file_path])
with open(log_file_path) as f:
assert f.read().startswith("2019-01-17T06:00:37,040 fake")
assert f.read().startswith(f"{FIXED_TIME_FORMAT} fake")


def test_log_unicode_messages(fixed_time: None, tmpdir: Path) -> None:
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from datetime import datetime
from threading import Thread
from unittest.mock import patch

Expand All @@ -18,11 +19,14 @@
class TestIndentingFormatter:
"""Test ``pip._internal.utils.logging.IndentingFormatter``."""

def convert_utc_timestamp_to_local(self, timestamp: float) -> float:
return datetime.utcfromtimestamp(timestamp).replace(tzinfo=None).timestamp()

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=self.convert_utc_timestamp_to_local(1547704837.040001),
msecs=40,
levelname=level_name,
levelno=level_number,
Expand Down