#314 Write mock config correctly when run in Py 3
Merged by cqi. Opened by cqi.
cqi/rpkg py3fix-config-mockbuild-dir  into  master

Download 314.patch

Mock config is a plain text file, so it is unnecessary to write in
binary mode. When run in Python 3, original code fails due to it writes
a unicode string in binary mode without encode in advance.

Tests are updated accordingly. Now, file operations like open and write
are not mocked, which can catch any potential issues happening during
those calls.

Signed-off-by: Chenxiong Qi cqi@redhat.com

rebased onto 2ed67e7529d2b90184b37a4b0622f634c2ba5727

I like less mocking, but with this patch tests on my machine do not pass anymore.

On 2.7:

======================================================================
ERROR: test_config_using_root_guessed_from_branch (test_commands.TestConfigMockConfigDir)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/lsedlar/repos/rpkg/.tox/py27/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/lsedlar/repos/rpkg/tests/test_commands.py", line 819, in test_config_using_root_guessed_from_branch
    self.cmd._config_dir_basic()
  File "/home/lsedlar/repos/rpkg/pyrpkg/__init__.py", line 2323, in _config_dir_basic
    f.write(config_content)
TypeError: write() argument 1 must be unicode, not str

On 2.6:

======================================================================
ERROR: test_config_using_root_guessed_from_branch (test_commands.TestConfigMockConfigDir)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/lsedlar/repos/rpkg/.tox/py26/lib/python2.6/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/home/lsedlar/repos/rpkg/tests/test_commands.py", line 819, in test_config_using_root_guessed_from_branch
    self.cmd._config_dir_basic()
  File "/home/lsedlar/repos/rpkg/pyrpkg/__init__.py", line 2323, in _config_dir_basic
    f.write(config_content)
  File "/usr/lib64/python2.6/io.py", line 1515, in write
    s.__class__.__name__)
TypeError: can't write str to text stream

rebased onto d81ffef38d75313fb7c790e70911a1fd577036da

pretty please pagure-ci rebuild

Looks good to me. Now it works fine :)

Pull-Request has been merged by cqi

Metadata