From 97d04555b80d1076f42c9f5e2842b8ed0b5ee8e2 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 9 May 2019 08:10:11 -0400 Subject: [PATCH] run tests in docker container --- .travis.yml | 19 +++++++------------ Dockerfile | 13 +++++++++++++ Makefile | 8 ++++++-- i3ipc/connection.py | 1 + run-tests.py | 4 +++- 5 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 Dockerfile diff --git a/.travis.yml b/.travis.yml index d0c6408..1f4648c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,8 @@ -language: python -sudo: required -dist: bionic -python: - - "3.6" +language: minimal +dist: xenial +services: + - docker before_install: - - /usr/lib/apt/apt-helper download-file http://debian.sur5r.net/i3/pool/main/s/sur5r-keyring/sur5r-keyring_2019.02.01_all.deb keyring.deb SHA256:176af52de1a976f103f9809920d80d02411ac5e763f695327de9fa6aff23f416 - - sudo dpkg -i ./keyring.deb - - echo "deb http://debian.sur5r.net/i3/ $(grep '^DISTRIB_CODENAME=' /etc/lsb-release | cut -f2 -d=) universe" | sudo tee /etc/apt/sources.list.d/sur5r-i3.list > /dev/null - - sudo apt-get update -qq - - sudo apt-get install xvfb i3 - - sudo pip install pytest -script: ./run-tests.py + - docker build -t i3ipc-python-test . +script: + - docker run -it i3ipc-python-test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4586a26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM ubuntu:19.04 + +WORKDIR /app + +RUN apt-get update && apt-get install -y python3-pip i3 xvfb + +COPY requirements.txt . +RUN pip3 install -r requirements.txt + +ADD . /app + +RUN find -name __pycache__ | xargs rm -r || true +CMD ["./run-tests.py"] diff --git a/Makefile b/Makefile index d72f850..2ee8ea1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test format lint all clean publish docs coverage +.PHONY: test format lint all clean publish docs coverage docker-test .DEFAULT_GOAL := all source_dirs = i3ipc test examples @@ -12,6 +12,10 @@ format: test: ./run-tests.py +docker-test: + docker build -t i3ipc-python-test . + docker run -it i3ipc-python-test + clean: rm -rf dist i3ipc.egg-info build docs/_build rm -rf `find -type d -name __pycache__` @@ -26,4 +30,4 @@ docs: livedocs: sphinx-autobuild docs docs/_build/html --watch i3ipc -i '*swp' -i '*~' -all: format lint test +all: format lint docker-test diff --git a/i3ipc/connection.py b/i3ipc/connection.py index 90ed223..b1b2cae 100644 --- a/i3ipc/connection.py +++ b/i3ipc/connection.py @@ -168,6 +168,7 @@ def message(self, message_type, payload): if not self.auto_reconnect: raise (e) + # XXX: can the socket path change between restarts? if not self._wait_for_socket(): raise (e) diff --git a/run-tests.py b/run-tests.py index 958034d..aab45b7 100755 --- a/run-tests.py +++ b/run-tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import subprocess from subprocess import Popen @@ -8,6 +8,7 @@ import sys import re import time +import random try: from shutil import which @@ -112,6 +113,7 @@ def run_pytest(display): env['DISPLAY'] = ':%d' % display env['PYTHONPATH'] = here env['_I3IPC_TEST'] = '1' + env['I3SOCK'] = f'/tmp/i3ipc-test-sock-{display}' subprocess.run([PYTEST], env=env)