Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

String handling causes tests to fail in python3 #9

Open
jeffbrl opened this issue Apr 6, 2017 · 5 comments
Open

String handling causes tests to fail in python3 #9

jeffbrl opened this issue Apr 6, 2017 · 5 comments

Comments

@jeffbrl
Copy link

jeffbrl commented Apr 6, 2017

@rdegges Thanks for writing this program. I'm would like to use it as a basis for developing a CLI app. I noticed that the unit tests are not properly accounting for python3 strings. I'm not certain how to fix this as I have not worked with subprocess.

(venv) dockerx@de8efbd3a5e2:~/PycharmProjects/skele-cli$ python3 --version
Python 3.4.3
(venv) dockerx@de8efbd3a5e2:~/PycharmProjects/skele-cli$ python3 setup.py test
running test
================================================================== test session starts ===================================================================
platform linux -- Python 3.4.3, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /home/dockerx/PycharmProjects/skele-cli, inifile:
plugins: cov-2.4.0
collected 4 items 

tests/test_cli.py FF
tests/commands/test_hello.py FF

----------- coverage: platform linux, python 3.4.3-final-0 -----------
Name                         Stmts   Miss  Cover   Missing
----------------------------------------------------------
skele/__init__.py                1      0   100%
skele/cli.py                    13      0   100%
skele/commands/__init__.py       1      0   100%
skele/commands/base.py           7      1    86%   13
skele/commands/hello.py          6      0   100%
----------------------------------------------------------
TOTAL                           28      1    96%


======================================================================== FAILURES ========================================================================
________________________________________________________ TestHelp.test_returns_usage_information _________________________________________________________

self = <test_cli.TestHelp testMethod=test_returns_usage_information>

    def test_returns_usage_information(self):
        output = popen(['skele', '-h'], stdout=PIPE).communicate()[0]
>       self.assertTrue('Usage:' in output)
E       TypeError: 'str' does not support the buffer interface

tests/test_cli.py:13: TypeError
______________________________________________________ TestVersion.test_returns_version_information ______________________________________________________

self = <test_cli.TestVersion testMethod=test_returns_version_information>

    def test_returns_version_information(self):
        output = popen(['skele', '--version'], stdout=PIPE).communicate()[0]
>       self.assertEqual(output.strip(), VERSION)
E       AssertionError: b'1.0.0' != '1.0.0'

tests/test_cli.py:22: AssertionError
___________________________________________________________ TestHello.test_returns_hello_world ___________________________________________________________

self = <test_hello.TestHello testMethod=test_returns_hello_world>

    def test_returns_hello_world(self):
        output = popen(['skele', 'hello'], stdout=PIPE).communicate()[0]
>       self.assertTrue('Hello, world!' in output)
E       TypeError: 'str' does not support the buffer interface

tests/commands/test_hello.py:16: TypeError
_________________________________________________________ TestHello.test_returns_multiple_lines __________________________________________________________

self = <test_hello.TestHello testMethod=test_returns_multiple_lines>

    def test_returns_multiple_lines(self):
        output = popen(['skele', 'hello'], stdout=PIPE).communicate()[0]
>       lines = output.split('\n')
E       TypeError: 'str' does not support the buffer interface

tests/commands/test_hello.py:11: TypeError
================================================================ 4 failed in 2.50 seconds ================================================================
(venv) dockerx@de8efbd3a5e2:~/PycharmProjects/skele-cli$ 
@jacobnosal
Copy link

@jeffbrl I have been working through this and have pinpointed the error in my fork of the project. I was able to fix the errors you're encountering in TestHelp.test_returns_usage_information and TestHelp.test_returns_version_information by encoding the strings to utf-8.

Change your assertions to the following:

self.assertTrue('Usage:'.encode('utf-8) in output)
...
self.assertEqual(output.strip(), VERSION.encode('utf-8'))

I'm newish to python but string encoding seems to be a persistent source of pain. Hope this helps.

@jeffbrl
Copy link
Author

jeffbrl commented Aug 3, 2017

Thanks, @jacobnosal.

@rdegges
Copy link
Owner

rdegges commented Dec 21, 2017

@jacobnosal wanna send a PR? <3

@jeffbrl
Copy link
Author

jeffbrl commented Mar 24, 2018

Sure, I can give it a shot.

@jeffbrl
Copy link
Author

jeffbrl commented Apr 13, 2018

I submitted PR #16

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants