Skip to content

Commit

Permalink
Fix tests requiring "struct_time" on Windows with Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jun 28, 2019
1 parent 8051c48 commit 25358e7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import os
import subprocess
import sys
import time
import warnings

Expand Down Expand Up @@ -73,9 +74,29 @@ def write(self, message):

@pytest.fixture
def monkeypatch_date(monkeypatch):

fix_struct = os.name == "nt" and sys.version_info < (3, 6)

def monkeypatch_date(year, month, day, hour, minute, second, microsecond, zone="UTC", offset=0):
dt = loguru._datetime.datetime(year, month, day, hour, minute, second, microsecond)
struct = time.struct_time([*dt.timetuple()] + [zone, offset])

if fix_struct:

class StructTime:
def __init__(self, struct, tm_zone, tm_gmtoff):
self._struct = struct
self.tm_zone = tm_zone
self.tm_gmtoff = tm_gmtoff

def __getattr__(self, name):
return getattr(self._struct, name)

def __iter__(self):
return iter(self._struct)

struct = StructTime(time.struct_time([*dt.timetuple()]), zone, offset)
else:
struct = time.struct_time([*dt.timetuple()] + [zone, offset])

def patched_now(tz=None):
return dt
Expand Down

0 comments on commit 25358e7

Please sign in to comment.