-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Python 3 fixes - fix dirutil, fileutil, and xml_parser tests #6229
Merged
stuhood
merged 4 commits into
pantsbuild:master
from
Eric-Arellano:py3-fixes_dirutil-tests
Jul 26, 2018
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ | |
import os | ||
import time | ||
import unittest | ||
from builtins import str | ||
from contextlib import contextmanager | ||
|
||
import mock | ||
from future.utils import text_type | ||
|
||
from pants.util import dirutil | ||
from pants.util.contextutil import pushd, temporary_dir | ||
|
@@ -120,10 +120,10 @@ def test_safe_walk(self): | |
# unicode constructor. | ||
with temporary_dir() as tmpdir: | ||
safe_mkdir(os.path.join(tmpdir, '中文')) | ||
if isinstance(tmpdir, text_type): | ||
if isinstance(tmpdir, str): | ||
tmpdir = tmpdir.encode('utf-8') | ||
for _, dirs, _ in dirutil.safe_walk(tmpdir): | ||
self.assertTrue(all(isinstance(dirname, text_type) for dirname in dirs)) | ||
self.assertTrue(all(isinstance(dirname, str) for dirname in dirs)) | ||
|
||
@contextmanager | ||
def tree(self): | ||
|
@@ -149,7 +149,7 @@ class Dir(datatype(['path'])): | |
class File(datatype(['path', 'contents'])): | ||
@classmethod | ||
def empty(cls, path): | ||
return cls(path, contents=b'') | ||
return cls(path, contents='') | ||
|
||
@classmethod | ||
def read(cls, root, relpath): | ||
|
@@ -194,11 +194,11 @@ def test_mergetree_existing(self): | |
self.Dir('a/b'), | ||
|
||
# Existing overlapping file should be overlayed. | ||
self.File('a/b/1', contents=b'1'), | ||
self.File('a/b/1', contents='1'), | ||
|
||
self.File.empty('a/b/2'), | ||
self.Dir('b'), | ||
self.File('b/1', contents=b'1'), | ||
self.File('b/1', contents='1'), | ||
self.File.empty('b/2'), | ||
self.Dir('c'), | ||
|
||
|
@@ -227,10 +227,10 @@ def test_mergetree_new(self): | |
self.Dir('a'), | ||
self.File.empty('a/2'), | ||
self.Dir('a/b'), | ||
self.File('a/b/1', contents=b'1'), | ||
self.File('a/b/1', contents='1'), | ||
self.File.empty('a/b/2'), | ||
self.Dir('b'), | ||
self.File('b/1', contents=b'1'), | ||
self.File('b/1', contents='1'), | ||
self.File.empty('b/2')) | ||
|
||
def test_mergetree_ignore_files(self): | ||
|
@@ -246,7 +246,7 @@ def ignore(root, names): | |
self.File.empty('a/2'), | ||
self.Dir('a/b'), | ||
self.Dir('b'), | ||
self.File('b/1', contents=b'1'), | ||
self.File('b/1', contents='1'), | ||
self.File.empty('b/2')) | ||
|
||
def test_mergetree_ignore_dirs(self): | ||
|
@@ -261,7 +261,7 @@ def ignore(root, names): | |
self.Dir('a'), | ||
self.File.empty('a/2'), | ||
self.Dir('b'), | ||
self.File('b/1', contents=b'1'), | ||
self.File('b/1', contents='1'), | ||
self.File.empty('b/2')) | ||
|
||
def test_mergetree_symlink(self): | ||
|
@@ -272,7 +272,7 @@ def test_mergetree_symlink(self): | |
self.Dir('a'), | ||
self.Symlink('a/2'), | ||
self.Dir('a/b'), | ||
self.File('a/b/1', contents=b'1'), | ||
self.File('a/b/1', contents='1'), | ||
self.File.empty('a/b/2'), | ||
|
||
# NB: assert_tree does not follow symlinks and so does not descend into the | ||
|
@@ -396,7 +396,7 @@ def test_rm_rf_no_such_file_not_an_error(self, file_name='./vanishing_file'): | |
def test_readwrite_file(self): | ||
with temporary_dir() as td: | ||
test_filename = os.path.join(td, 'test.out') | ||
test_content = '3333' | ||
test_content = b'3333' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must be bytes for |
||
safe_file_dump(test_filename, test_content) | ||
self.assertEqual(read_file(test_filename), test_content) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout the tests for comparing trees,
contents
was being encoded as byte strings in the expected output. I'm not sure why - the tests pass when unicode in Py2, and the bytes present an issue when using Py3.