# HG changeset patch # User Edwin Takahashi # Date 1576293045 0 # Node ID 9ffd4ecbfc2b3b9255e66588111a0af2140d0559 # Parent 0c13995b0aef5c8ea8409961f5bb5f3857a1576e Bug 1428705 - fix manifestparser/manifestparser for python3 and enable test_convert_directory.py r=ahal Changes: Import the appropriate version of `StringIO` instead of `BytesIO` depending on the version of python, and use it in `manifestparser.py`. This is required for `test_convert_directory.py` to pass on both python versions. Changes to the test was not required. Differential Revision: https://phabricator.services.mozilla.com/D56865 diff --git a/testing/mozbase/manifestparser/manifestparser/manifestparser.py b/testing/mozbase/manifestparser/manifestparser/manifestparser.py --- a/testing/mozbase/manifestparser/manifestparser/manifestparser.py +++ b/testing/mozbase/manifestparser/manifestparser/manifestparser.py @@ -1,23 +1,22 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. from __future__ import absolute_import, print_function -from io import BytesIO import json import fnmatch import os import shutil import sys import types -from six import string_types +from six import string_types, StringIO from .ini import read_ini from .filters import ( DEFAULT_FILTERS, enabled, exists as _exists, filterlist, ) @@ -504,17 +503,17 @@ class ManifestParser(object): print('%s = %s' % (key, test[key]), file=fp) print(file=fp) if close: # close the created file fp.close() def __str__(self): - fp = BytesIO() + fp = StringIO() self.write(fp=fp) value = fp.getvalue() return value def copy(self, directory, rootdir=None, *tags, **kwargs): """ copy the manifests and associated tests - directory : directory to copy to @@ -713,47 +712,49 @@ class ManifestParser(object): @classmethod def from_directories(cls, directories, pattern=None, ignore=(), write=None, relative_to=None): """ convert directories to a simple manifest; returns ManifestParser instance pattern -- shell pattern (glob) or patterns of filenames to match ignore -- directory names to ignore write -- filename or file-like object of manifests to write; - if `None` then a BytesIO instance will be created + if `None` then a StringIO instance will be created relative_to -- write paths relative to this path; if false then the paths are absolute """ # determine output opened_manifest_file = None # name of opened manifest file absolute = not relative_to # whether to output absolute path names as names if isinstance(write, string_types): opened_manifest_file = write write = open(write, 'w') if write is None: - write = BytesIO() + write = StringIO() # walk the directories, generating manifests def callback(directory, dirpath, dirnames, filenames): # absolute paths filenames = [os.path.join(dirpath, filename) for filename in filenames] # ensure new manifest isn't added filenames = [filename for filename in filenames if filename != opened_manifest_file] # normalize paths if not absolute and relative_to: filenames = [relpath(filename, relative_to) for filename in filenames] # write to manifest - print('\n'.join(['[%s]' % denormalize_path(filename) - for filename in filenames]), file=write) + write_content = '\n'.join([ + '[{}]'.format(denormalize_path(filename)) for filename in filenames + ]) + print(write_content, file=write) cls._walk_directories(directories, callback, pattern=pattern, ignore=ignore) if opened_manifest_file: # close file write.close() manifests = [opened_manifest_file] else: diff --git a/testing/mozbase/manifestparser/tests/manifest.ini b/testing/mozbase/manifestparser/tests/manifest.ini --- a/testing/mozbase/manifestparser/tests/manifest.ini +++ b/testing/mozbase/manifestparser/tests/manifest.ini @@ -1,14 +1,13 @@ [DEFAULT] subsuite = mozbase [test_expressionparser.py] [test_manifestparser.py] [test_testmanifest.py] [test_read_ini.py] [test_convert_directory.py] -skip-if = python == 3 [test_filters.py] [test_chunking.py] skip-if = python == 3 [test_convert_symlinks.py] disabled = https://bugzilla.mozilla.org/show_bug.cgi?id=920938