From 492599f0728357e09b9fa340753b88fc08fea679 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 19 Feb 2018 12:34:55 -0800 Subject: [PATCH 1/4] turn on appveyor (windows CI) --- .appveyor.yml | 56 ++++++++++++++++++++++++++++++++++++++++++ misc/windows-build.cmd | 21 ++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .appveyor.yml create mode 100644 misc/windows-build.cmd diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..5f17e37 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,56 @@ +# adapted from https://packaging.python.org/en/latest/appveyor/ + + +environment: + # we tell Tox to use "twisted[windows]", to get pypiwin32 installed + #TWISTED_EXTRAS: "[windows]" + # that didn't work (it seems to work when I run it locally, but on appveyor + # it fails to install the pypiwin32 package). So don't bother telling + # Twisted to support windows: just install it ourselves. + # EXTRA_DEPENDENCY: "pypiwin32" + matrix: + # For Python versions available on Appveyor, see + # http://www.appveyor.com/docs/installed-software#python + - PYTHON: "C:\\Python27" + - PYTHON: "C:\\Python27-x64" + DISTUTILS_USE_SDK: "1" + - PYTHON: "C:\\Python34" + - PYTHON: "C:\\Python35" + - PYTHON: "C:\\Python36" + - PYTHON: "C:\\Python36-x64" + +install: + - | + %PYTHON%\python.exe -m pip install wheel tox + +# note: +# %PYTHON% has: python.exe +# %PYTHON%\Scripts has: pip.exe, tox.exe (and others installed by bare pip) + + +build: off + +test_script: + # Put your test command here. + # Note that you must use the environment variable %PYTHON% to refer to + # the interpreter you're using - Appveyor does not do anything special + # to put the Python evrsion you want to use on PATH. + - | + misc\windows-build.cmd %PYTHON%\Scripts\tox.exe -e py + +after_test: + # This step builds your wheels. + # Again, you only need build.cmd if you're building C extensions for + # 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct + # interpreter + - | + misc\windows-build.cmd %PYTHON%\python.exe setup.py bdist_wheel + +artifacts: + # bdist_wheel puts your built wheel in the dist directory + - path: dist\* + +#on_success: +# You can use this step to upload your artifacts to a public website. +# See Appveyor's documentation for more details. Or you can simply +# access your wheels from the Appveyor "artifacts" tab for your build. diff --git a/misc/windows-build.cmd b/misc/windows-build.cmd new file mode 100644 index 0000000..243dc9a --- /dev/null +++ b/misc/windows-build.cmd @@ -0,0 +1,21 @@ +@echo off +:: To build extensions for 64 bit Python 3, we need to configure environment +:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 4 +:: +:: More details at: +:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows + +IF "%DISTUTILS_USE_SDK%"=="1" ( + ECHO Configuring environment to build with MSVC on a 64bit architecture + ECHO Using Windows SDK 7.1 + "C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\WindowsSdkVer.exe" -q -version:v7.1 + CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 /release + SET MSSdk=1 + REM Need the following to allow tox to see the SDK compiler + SET TOX_TESTENV_PASSENV=DISTUTILS_USE_SDK MSSdk INCLUDE LIB +) ELSE ( + ECHO Using default MSVC build environment +) + +CALL %* From 1e663aa5ef2b1089959809dc6dc1f2825fb5c039 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 19 Feb 2018 12:41:31 -0800 Subject: [PATCH 2/4] README: add appveyor badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 76296de..4fc0e02 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![PyPI](http://img.shields.io/pypi/v/magic-wormhole-transit-relay.svg)](https://pypi.python.org/pypi/magic-wormhole-transit-relay) [![Build Status](https://travis-ci.org/warner/magic-wormhole-transit-relay.svg?branch=master)](https://travis-ci.org/warner/magic-wormhole-transit-relay) +[![Windows Build Status](https://ci.appveyor.com/api/projects/status/61kgarqikolbvj1m/branch/master?svg=true)](https://ci.appveyor.com/project/warner/magic-wormhole-transit-relay) [![codecov.io](https://codecov.io/github/warner/magic-wormhole-transit-relay/coverage.svg?branch=master)](https://codecov.io/github/warner/magic-wormhole-transit-relay?branch=master) From 071471a353076746df0f9b9f56459eaf6815cc6f Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 19 Feb 2018 13:12:14 -0800 Subject: [PATCH 3/4] test_stats: mock time.time() with a float, to appease windows For some reason, the appveyor (windows) tests fail on py36 with an OSError during an internal (twisted.python.log) call to datetime.fromtimestamp(). It's possible that my mock times are too old (I'm using made-up values like "456"), but maybe it's just that real time.time() returns a float instead of an integer. --- src/wormhole_transit_relay/test/test_stats.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wormhole_transit_relay/test/test_stats.py b/src/wormhole_transit_relay/test/test_stats.py index 56e8c98..ae37790 100644 --- a/src/wormhole_transit_relay/test/test_stats.py +++ b/src/wormhole_transit_relay/test/test_stats.py @@ -15,11 +15,11 @@ class DB(unittest.TestCase): d = self.mktemp() os.mkdir(d) usage_db = os.path.join(d, "usage.sqlite") - with mock.patch("time.time", return_value=456): + with mock.patch("time.time", return_value=456.0): t = Transit(blur_usage=None, log_file=None, usage_db=usage_db) db = self.open_db(usage_db) - with mock.patch("time.time", return_value=457): + with mock.patch("time.time", return_value=457.0): t.recordUsage(started=123, result="happy", total_bytes=100, total_time=10, waiting_time=2) self.assertEqual(db.execute("SELECT * FROM `usage`").fetchall(), @@ -31,7 +31,7 @@ class DB(unittest.TestCase): incomplete_bytes=0, waiting=0, connected=0)) - with mock.patch("time.time", return_value=458): + with mock.patch("time.time", return_value=458.0): t.recordUsage(started=150, result="errory", total_bytes=200, total_time=11, waiting_time=3) self.assertEqual(db.execute("SELECT * FROM `usage`").fetchall(), @@ -45,7 +45,7 @@ class DB(unittest.TestCase): incomplete_bytes=0, waiting=0, connected=0)) - with mock.patch("time.time", return_value=459): + with mock.patch("time.time", return_value=459.0): t.timerUpdateStats() self.assertEqual(db.execute("SELECT * FROM `current`").fetchone(), dict(rebooted=456, updated=459, From a9680918b96030cfae36ea5dcf3164d6075c6ab6 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 19 Feb 2018 13:23:40 -0800 Subject: [PATCH 4/4] test_stats: try more realistic fake time.time() Maybe windows+py36 was failing because "456" is too small of a value, and the OS time libraries can't figure out UTC for something back in 1970. Switch to a fixed timestamp from just a few minutes ago, to see if it likes 2018 better. --- src/wormhole_transit_relay/test/test_stats.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wormhole_transit_relay/test/test_stats.py b/src/wormhole_transit_relay/test/test_stats.py index ae37790..f9433ef 100644 --- a/src/wormhole_transit_relay/test/test_stats.py +++ b/src/wormhole_transit_relay/test/test_stats.py @@ -12,14 +12,15 @@ class DB(unittest.TestCase): return db def test_db(self): + T = 1519075308.0 d = self.mktemp() os.mkdir(d) usage_db = os.path.join(d, "usage.sqlite") - with mock.patch("time.time", return_value=456.0): + with mock.patch("time.time", return_value=T+0): t = Transit(blur_usage=None, log_file=None, usage_db=usage_db) db = self.open_db(usage_db) - with mock.patch("time.time", return_value=457.0): + with mock.patch("time.time", return_value=T+1): t.recordUsage(started=123, result="happy", total_bytes=100, total_time=10, waiting_time=2) self.assertEqual(db.execute("SELECT * FROM `usage`").fetchall(), @@ -27,11 +28,11 @@ class DB(unittest.TestCase): total_bytes=100, total_time=10, waiting_time=2), ]) self.assertEqual(db.execute("SELECT * FROM `current`").fetchone(), - dict(rebooted=456, updated=457, + dict(rebooted=T+0, updated=T+1, incomplete_bytes=0, waiting=0, connected=0)) - with mock.patch("time.time", return_value=458.0): + with mock.patch("time.time", return_value=T+2): t.recordUsage(started=150, result="errory", total_bytes=200, total_time=11, waiting_time=3) self.assertEqual(db.execute("SELECT * FROM `usage`").fetchall(), @@ -41,14 +42,14 @@ class DB(unittest.TestCase): total_bytes=200, total_time=11, waiting_time=3), ]) self.assertEqual(db.execute("SELECT * FROM `current`").fetchone(), - dict(rebooted=456, updated=458, + dict(rebooted=T+0, updated=T+2, incomplete_bytes=0, waiting=0, connected=0)) - with mock.patch("time.time", return_value=459.0): + with mock.patch("time.time", return_value=T+3): t.timerUpdateStats() self.assertEqual(db.execute("SELECT * FROM `current`").fetchone(), - dict(rebooted=456, updated=459, + dict(rebooted=T+0, updated=T+3, incomplete_bytes=0, waiting=0, connected=0))