diff --git a/.travis.yml b/.travis.yml index 89a7792..7ace838 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,17 +23,29 @@ language: python matrix: include: - python: "2.7" - env: REQUIREMENTS=requirements-dev.txt VENV=python2.7 + env: REQUIREMENTS=requirements-dev.txt services: - docker - python: "pypy" - env: REQUIREMENTS=requirements-dev.txt VENV=pypy + env: REQUIREMENTS=requirements-dev.txt + group: deprecated-2017Q2 services: - docker - python: "3.4" - env: REQUIREMENTS=requirements3-dev.txt VENV=python3.4 + env: REQUIREMENTS=requirements3-dev.txt + services: + - docker + - python: "3.5" + env: REQUIREMENTS=requirements3-dev.txt + services: + - docker + - python: "3.6" + env: REQUIREMENTS=requirements3-dev.txt services: - docker install: pip install -r $REQUIREMENTS -script: py.test -q tests && behave -c --no-capture -q +script: + - py.test -q tests + - behave -c --no-capture -q +cache: pip diff --git a/features/environment.py b/features/environment.py index 964dcbf..e188498 100644 --- a/features/environment.py +++ b/features/environment.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + from docker.errors import NotFound from utils import get_client @@ -44,3 +46,8 @@ def after_scenario(ctx, scenario): ctx.client.remove_container(ctx.container, force=True) except: pass + + +def before_scenario(context, scenario): + if "skip3" in scenario.effective_tags and sys.version_info >= (3,0): + scenario.skip("Marked with @skip3 and running on Python 3") diff --git a/features/exec_non_interactive.feature b/features/exec_non_interactive.feature index 766321d..bdf05da 100644 --- a/features/exec_non_interactive.feature +++ b/features/exec_non_interactive.feature @@ -25,9 +25,9 @@ Feature: Executing command in a running docker container non-interactively And I run "cat" in a docker container with stdin open And I start the container When I exec "/bin/tail -f -n1 /etc/passwd" in a running docker container - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -36,9 +36,9 @@ Feature: Executing command in a running docker container non-interactively And I run "cat" in a docker container with stdin open And I start the container When I exec "sh -c 'tail -f -n1 /etc/passwd 1>&2'" in a running docker container - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -48,8 +48,8 @@ Feature: Executing command in a running docker container non-interactively And I start the container When I exec "/bin/tail -f -n1 /etc/passwd" in a running docker container And I press ENTER - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ And The container will still be running diff --git a/features/interactive_stdin.feature b/features/interactive_stdin.feature index 3e0add5..1c775c5 100644 --- a/features/interactive_stdin.feature +++ b/features/interactive_stdin.feature @@ -24,9 +24,9 @@ Feature: Attaching to a docker container with stdin open Given I am using a TTY And I run "tail -n1 -f /etc/passwd" in a docker container with stdin open When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -76,6 +76,7 @@ Feature: Attaching to a docker container with stdin open """ + @skip3 Scenario: Closing input Given I am using a TTY And I run "/bin/cat" in a docker container with stdin open diff --git a/features/non_interactive.feature b/features/non_interactive.feature index 9a4f5c5..0ce7c2e 100644 --- a/features/non_interactive.feature +++ b/features/non_interactive.feature @@ -24,9 +24,9 @@ Feature: Attaching to a docker container non-interactively Given I am using a TTY And I run "/bin/tail -f -n1 /etc/passwd" in a docker container When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ @@ -34,19 +34,21 @@ Feature: Attaching to a docker container non-interactively Given I am using a TTY And I run "sh -c 'tail -f -n1 /etc/passwd 1>&2'" in a docker container When I start dockerpty - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ + + Scenario: Ignoring input Given I am using a TTY And I run "/bin/tail -n1 -f /etc/passwd" in a docker container When I start dockerpty And I press ENTER - Then I will see the output + Then I will see output matching """ - nobody:x:99:99:nobody:/home:/bin/false + ^nobody:x:\d+:\d+:nobody:/home:/bin/false$ """ And The container will still be running diff --git a/features/steps/step_definitions.py b/features/steps/step_definitions.py index 2ac575f..74121cc 100644 --- a/features/steps/step_definitions.py +++ b/features/steps/step_definitions.py @@ -15,7 +15,7 @@ # limitations under the License. from behave import then, given, when -from expects import expect, equal, be_true, be_false +from expects import expect, equal, be_true, be_false, match import tests.util as util import dockerpty @@ -197,6 +197,14 @@ def step_impl(ctx): expect(actual[-len(wanted):]).to(equal(wanted)) +@then('I will see output matching') +def step_impl(ctx): + # you should check `actual` when tests fail + actual = util.read_printable(ctx.pty) + wanted = ctx.text + expect(actual).to(match(wanted)) + + @then('The PTY will be closed cleanly') def step_impl(ctx): if not hasattr(ctx, "exit_code"): diff --git a/tox.ini b/tox.ini index 444b01d..06678d3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,11 @@ [tox] -envlist = py27, pypy, py34 +envlist = py27, pypy, pypy3, py3{4,5,6} [testenv] deps = py27: -rrequirements-dev.txt pypy: -rrequirements-dev.txt - py34: -rrequirements3-dev.txt + py3{4,5,6}: -rrequirements3-dev.txt commands = py.test -v tests/ behave