diff options
Diffstat (limited to 'tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py')
-rw-r--r-- | tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py b/tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py index 1528cbb8341..fa704bf6dbc 100644 --- a/tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py +++ b/tests/wpt/web-platform-tests/css/tools/w3ctestlib/Sources.py @@ -525,7 +525,8 @@ class FileSource: def data(self): """Return file contents as a byte string.""" if (self._data is None): - self._data = open(self.sourcepath, 'r').read() + with open(self.sourcepath, 'r') as f: + self._data = f.read() if (self._data.startswith(codecs.BOM_UTF8)): self.encoding = 'utf-8-sig' # XXX look for other unicode BOMs return self._data @@ -580,8 +581,8 @@ class FileSource: def write(self, format): """Writes FileSource.data() out to `self.relpath` through Format `format`.""" data = self.data() - f = open(format.dest(self.relpath), 'w') - f.write(data) + with open(format.dest(self.relpath), 'w') as f: + f.write(data) if (self.metaSource): self.metaSource.write(format) # XXX need to get output path from format, but not let it choose actual format @@ -818,7 +819,8 @@ class ConfigSource(FileSource): """Merge contents of all config files represented by this source.""" data = '' for src in self.sourcepath: - data += open(src).read() + with open(src) as f: + data += f.read() data += '\n' return data @@ -868,35 +870,36 @@ class ReftestManifest(ConfigSource): for src in self.sourcepath: relbase = basepath(self.relpath) srcbase = basepath(src) - for line in open(src): - strip = self.baseRE.search(line) - if strip: - striplist.append(strip.group(1)) - line = self.stripRE.sub('', line) - m = self.parseRE.search(line) - if m: - record = ((join(srcbase, m.group(2)), join(srcbase, m.group(3))), \ - (join(relbase, m.group(2)), join(relbase, m.group(3))), \ - m.group(1)) -# for strip in striplist: - # strip relrecord - if not exists(record[0][0]): - raise ReftestFilepathError("Manifest Error in %s: " - "Reftest test file %s does not exist." \ - % (src, record[0][0])) - elif not exists(record[0][1]): - raise ReftestFilepathError("Manifest Error in %s: " - "Reftest reference file %s does not exist." \ - % (src, record[0][1])) - elif not isPathInsideBase(record[1][0]): - raise ReftestFilepathError("Manifest Error in %s: " - "Reftest test replath %s not within relpath root." \ - % (src, record[1][0])) - elif not isPathInsideBase(record[1][1]): - raise ReftestFilepathError("Manifest Error in %s: " - "Reftest test replath %s not within relpath root." \ - % (src, record[1][1])) - yield record + with open(src) as f: + for line in f: + strip = self.baseRE.search(line) + if strip: + striplist.append(strip.group(1)) + line = self.stripRE.sub('', line) + m = self.parseRE.search(line) + if m: + record = ((join(srcbase, m.group(2)), join(srcbase, m.group(3))), \ + (join(relbase, m.group(2)), join(relbase, m.group(3))), \ + m.group(1)) + # for strip in striplist: + # strip relrecord + if not exists(record[0][0]): + raise ReftestFilepathError("Manifest Error in %s: " + "Reftest test file %s does not exist." \ + % (src, record[0][0])) + elif not exists(record[0][1]): + raise ReftestFilepathError("Manifest Error in %s: " + "Reftest reference file %s does not exist." \ + % (src, record[0][1])) + elif not isPathInsideBase(record[1][0]): + raise ReftestFilepathError("Manifest Error in %s: " + "Reftest test replath %s not within relpath root." \ + % (src, record[1][0])) + elif not isPathInsideBase(record[1][1]): + raise ReftestFilepathError("Manifest Error in %s: " + "Reftest test replath %s not within relpath root." \ + % (src, record[1][1])) + yield record import Utils # set up XML catalog xhtmlns = '{http://www.w3.org/1999/xhtml}' @@ -1026,9 +1029,8 @@ class XMLSource(FileSource): output = self.unicode() # write - f = open(format.dest(self.relpath), 'w') - f.write(output.encode(self.encoding, 'xmlcharrefreplace')) - f.close() + with open(format.dest(self.relpath), 'w') as f: + f.write(output.encode(self.encoding, 'xmlcharrefreplace')) def compact(self): self.tree = None |