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

Update to Python 3 #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.tox
.coverage
__pycache__
.mypy_cache/
site/
dist/
docs/steps/*
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "2.7"
- "3.6"

matrix:
fast_finish: true
Expand All @@ -17,8 +17,8 @@ env:
script:
- tox -e flake8
- tox -e isort
- tox -e py27
- tox -e py27-docs
- tox -e py3
- tox -e py3-docs

after_success:
- tox -e deploy-docs
2 changes: 1 addition & 1 deletion cli_bdd/behave/steps/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
base_steps=base_steps
)
locals().update(steps)
__all__ = steps.keys()
__all__ = list(steps.keys())
2 changes: 1 addition & 1 deletion cli_bdd/behave/steps/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
base_steps=base_steps
)
locals().update(steps)
__all__ = steps.keys()
__all__ = list(steps.keys())
2 changes: 1 addition & 1 deletion cli_bdd/behave/steps/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
base_steps=base_steps
)
locals().update(steps)
__all__ = steps.keys()
__all__ = list(steps.keys())
2 changes: 1 addition & 1 deletion cli_bdd/behave/steps/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}


class BehaveStepMixin(object):
class BehaveStepMixin:
def build_step_func(self):
decorator = DECORATORS_BY_TYPES[self.type_]
use_step_matcher('re')
Expand Down
2 changes: 1 addition & 1 deletion cli_bdd/core/steps/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


class StepBase(object):
class StepBase:
type_ = None # given, when, then
sentence = None
func_name = None
Expand Down
15 changes: 9 additions & 6 deletions cli_bdd/core/steps/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import difflib
import StringIO
import io

import pexpect
from hamcrest import (
Expand All @@ -18,9 +18,10 @@


def run(command, fail_on_error=False, interactively=False, timeout=30):
child = pexpect.spawn('/bin/sh', ['-c', command], echo=False)
child.logfile_read = StringIO.StringIO()
child.logfile_send = StringIO.StringIO()
child = pexpect.spawn('/bin/sh', ['-c', command], echo=False,
encoding='utf-8')
child.logfile_read = io.StringIO()
child.logfile_send = io.StringIO()
if not interactively:
child.expect(pexpect.EOF, timeout=timeout)
if fail_on_error and child.exitstatus > 0:
Expand Down Expand Up @@ -188,12 +189,14 @@ def step(self, output, should_not=False, exactly=False):

# todo: separate stdout and stderr
# todo: test replace
data = child.logfile_read.getvalue().replace('\r\n', '\n')
# note: unhappy about stripping null characters here.
data = child.logfile_read.getvalue().replace('\r\n', '\n') \
.replace('\x00', '')
data_lines = data.splitlines()
if data.endswith('\n'):
data_lines.append('')

expected = self.get_text().encode('utf-8') # todo: test encode
expected = self.get_text()
expected_lines = expected.splitlines()
if expected.endswith('\n'):
expected_lines.append('')
Expand Down
Empty file removed cli_bdd/lettuce/__init__.py
Empty file.
4 changes: 0 additions & 4 deletions cli_bdd/lettuce/steps/__init__.py

This file was deleted.

10 changes: 0 additions & 10 deletions cli_bdd/lettuce/steps/command.py

This file was deleted.

10 changes: 0 additions & 10 deletions cli_bdd/lettuce/steps/environment.py

This file was deleted.

10 changes: 0 additions & 10 deletions cli_bdd/lettuce/steps/file.py

This file was deleted.

20 changes: 0 additions & 20 deletions cli_bdd/lettuce/steps/mixins.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _prepare_docstring(value):
return re.sub(
r'^ {%s}' % remove_spaces,
'',
unicode(value),
str(value),
flags=re.MULTILINE
).strip()

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ Installation:
$ pip install cli-bdd
```

Read the docs how to use `cli-bdd` with [behave](/behave/) and [lettuce](/lettuce/).
Read the docs how to use `cli-bdd` with [behave](/behave/).
16 changes: 0 additions & 16 deletions docs/lettuce.md

This file was deleted.

2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def serve_docs():
@task(name='generate-api-reference')
def generate_api_reference():
from docs.generator import generate_api_reference
print 'Generating API reference'
print('Generating API reference')
generate_api_reference()
8 changes: 4 additions & 4 deletions tests/functional/behave/features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Feature: showing off cli-bdd
Scenario: login with CLI
Given a file "/tmp/login.py" with:
"""
login = raw_input('Login: ')
password = raw_input('Password: ')
print 'Welcome %s!' % login
print 'Your password is "%s"' % password
login = input('Login: ')
password = input('Password: ')
print('Welcome {}!'.format(login))
print('Your password is "{}"'.format(password))
"""
When I run `python /tmp/login.py` interactively
And I got "Login: " for interactive dialog
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/behave/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_me(self):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).communicate()[0].strip()
).communicate()[0].decode().strip()
stdout_lines = stdout.split('\n')
assert_that(
stdout_lines[-4],
Expand Down
Empty file.
Empty file.
2 changes: 0 additions & 2 deletions tests/functional/lettuce/features/steps.py

This file was deleted.

21 changes: 0 additions & 21 deletions tests/functional/lettuce/features/test.feature

This file was deleted.

36 changes: 0 additions & 36 deletions tests/functional/lettuce/tests.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/functional/login.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
login = raw_input('Login:')
password = raw_input('Password:')
print '%s %s' % (login, password)
login = input('Login:')
password = input('Password:')
print('%s %s' % (login, password))
24 changes: 2 additions & 22 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from hamcrest import assert_that, equal_to

from cli_bdd.behave import steps as behave_steps_root_module
from cli_bdd.lettuce import steps as lettuce_steps_root_module
from cli_bdd.lettuce.steps.mixins import LettuceStepMixin
from mock import Mock, patch
from mock import Mock


class TestCase(unittest.TestCase):
Expand All @@ -18,7 +16,7 @@ class StepsSentenceRegexTestMixin(object):
steps = None

def test_experiments(self):
for step_func_name, step_exp in self.step_experiments.items():
for step_func_name, step_exp in list(self.step_experiments.items()):
sentence = self._get_sentence_by_step_func_name(step_func_name)
for exp in step_exp:
result = re.search(sentence, exp['value'])
Expand Down Expand Up @@ -82,21 +80,3 @@ def _execute_module_step(self, name, context, kwargs, table, text):
context.text = text
getattr(self.module, name)(context, **kwargs)
return context


class LettuceStepsTestMixin(StepsTestMixin):
module = None
root_module = lettuce_steps_root_module

def _execute_module_step(self, name, context, kwargs, table, text):
step_context = Mock()
step_context.hashes = table
step_context.multiline = text

with patch.object(
LettuceStepMixin,
'get_scenario_context',
lambda self: context
):
getattr(self.module, name)(step_context, **kwargs)
return context
14 changes: 3 additions & 11 deletions tests/unit/steps/command/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

from cli_bdd.behave.steps import command as behave_command
from cli_bdd.core.steps.command import base_steps
from cli_bdd.lettuce.steps import command as lettuce_command
from testutils import (
BehaveStepsTestMixin,
LettuceStepsTestMixin,
StepsSentenceRegexTestMixin,
TestCase
)
Expand Down Expand Up @@ -62,7 +60,7 @@ def test_successfully_run_command(self):

def test_run_command_interactively(self):
file_path = os.path.join(tempfile.gettempdir(), 'test_interactive.txt')
with open(file_path, 'wr') as ff:
with open(file_path, 'w+') as ff:
ff.write('Some text')

context = self.execute_module_step(
Expand All @@ -84,7 +82,7 @@ def test_run_command_interactively(self):

def test_type_into_command(self):
file_path = os.path.join(tempfile.gettempdir(), 'test_interactive.txt')
with open(file_path, 'wr') as ff:
with open(file_path, 'w+') as ff:
ff.write('Some text')

context = self.execute_module_step(
Expand Down Expand Up @@ -112,7 +110,7 @@ def test_type_into_command(self):

def test_got_interactive_dialog(self):
file_path = os.path.join(tempfile.gettempdir(), 'test_interactive.txt')
with open(file_path, 'wr') as ff:
with open(file_path, 'w+') as ff:
ff.write('Some text')

for matcher, valid in (
Expand Down Expand Up @@ -717,9 +715,3 @@ class TestCommandBehaveSteps(BehaveStepsTestMixin,
CommandStepsMixin,
TestCase):
module = behave_command


class TestCommandLettuceSteps(LettuceStepsTestMixin,
CommandStepsMixin,
TestCase):
module = lettuce_command
Loading