[Piglit] [PATCH 36/42] framework/tests: Rename with_tempfile function to just tempfile
Dylan Baker
baker.dylan.c at gmail.com
Wed Apr 22 15:10:25 PDT 2015
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/tests/core_tests.py | 6 +++---
framework/tests/glsl_parser_test_tests.py | 20 ++++++++++----------
framework/tests/json_backend_tests.py | 2 +-
framework/tests/json_results_update_tests.py | 16 ++++++++--------
framework/tests/shader_test_tests.py | 6 +++---
framework/tests/summary_tests.py | 6 +++---
framework/tests/utils.py | 14 +++++++-------
7 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/framework/tests/core_tests.py b/framework/tests/core_tests.py
index f080d9e..d3ca563 100644
--- a/framework/tests/core_tests.py
+++ b/framework/tests/core_tests.py
@@ -108,7 +108,7 @@ def test_parse_listfile_return():
"""
contents = "/tmp/foo\n/tmp/bar\n"
- with utils.with_tempfile(contents) as tfile:
+ with utils.tempfile(contents) as tfile:
results = core.parse_listfile(tfile)
assert isinstance(results, collections.Container)
@@ -119,7 +119,7 @@ class Test_parse_listfile_TrailingWhitespace(object):
@classmethod
def setup_class(cls):
contents = "/tmp/foo\n/tmp/foo \n/tmp/foo\t\n"
- with utils.with_tempfile(contents) as tfile:
+ with utils.tempfile(contents) as tfile:
cls.results = core.parse_listfile(tfile)
def test_newlines(self):
@@ -149,7 +149,7 @@ def test_parse_listfile_tilde():
"""
contents = "~/foo\n"
- with utils.with_tempfile(contents) as tfile:
+ with utils.tempfile(contents) as tfile:
results = core.parse_listfile(tfile)
assert results[0] == os.path.expandvars("$HOME/foo")
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index 7ddd298..ce36281 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -38,7 +38,7 @@ sys.stderr = sys.stdout
def _check_config(content):
""" This is the test that actually checks the glsl config section """
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
return glsl.GLSLParserTest(tfile), tfile
@@ -48,7 +48,7 @@ def test_no_config_start():
content = ('// expect_result: pass\n'
'// glsl_version: 1.00\n'
'// [end config]\n')
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(glsl.GLSLParserNoConfigError) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_equal(
@@ -62,7 +62,7 @@ def test_find_config_start():
content = ('// [config]\n'
'// glsl_version: 1.00\n'
'//\n')
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(SystemExit) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_not_equal(
@@ -73,7 +73,7 @@ def test_find_config_start():
def test_no_config_end():
"""test.glsl_parser_test.GLSLParserTest: exception is raised if [end config] section is missing
"""
- with utils.with_tempfile('// [config]\n') as tfile:
+ with utils.tempfile('// [config]\n') as tfile:
with nt.assert_raises(SystemExit) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_equal(
@@ -87,7 +87,7 @@ def test_no_expect_result():
content = ('// [config]\n'
'// glsl_version: 1.00\n'
'//\n')
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(SystemExit) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_equal(
@@ -102,7 +102,7 @@ def test_no_glsl_version():
content = ('// [config]\n'
'// expect_result: pass\n'
'// [end config]\n')
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(SystemExit) as exc:
glsl.GLSLParserTest(tfile)
nt.assert_equal(
@@ -226,7 +226,7 @@ def test_bad_section_name():
'// new_awesome_key: foo\n'
'// [end config]\n')
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(SystemExit) as e:
glsl.GLSLParserTest(tfile)
@@ -252,7 +252,7 @@ def test_good_section_names():
def check_no_duplicates(content, dup):
""" Ensure that duplicate entries raise an error """
- with utils.with_tempfile(content) as tfile:
+ with utils.tempfile(content) as tfile:
with nt.assert_raises(SystemExit) as e:
glsl.GLSLParserTest(tfile)
@@ -314,7 +314,7 @@ def glslparser_exetensions_seperators():
for name, value in problems:
test = content.format(value)
- with utils.with_tempfile(test) as tfile:
+ with utils.tempfile(test) as tfile:
check_bad_character.description = (
'test.glsl_parser_test.GLSLParserTest: require_extensions {0} '
'should raise an error'.format(name))
@@ -351,5 +351,5 @@ def test_good_extensions():
'test.glsl_parser_test.GLSLParserTest: '
'require_extension {} is valid'.format(x))
- with utils.with_tempfile(test) as tfile:
+ with utils.tempfile(test) as tfile:
yield check_good_extension, tfile, x
diff --git a/framework/tests/json_backend_tests.py b/framework/tests/json_backend_tests.py
index 10ab8a6..c3f11fe 100644
--- a/framework/tests/json_backend_tests.py
+++ b/framework/tests/json_backend_tests.py
@@ -177,7 +177,7 @@ def test_update_results_old():
@nt.raises(AssertionError)
def test_json_resume_non_folder():
"""backends.json._resume: doesn't accept a file"""
- with utils.with_tempfile('') as f:
+ with utils.tempfile('') as f:
backends.json._resume(f)
diff --git a/framework/tests/json_results_update_tests.py b/framework/tests/json_results_update_tests.py
index 67360f5..75e60f2 100644
--- a/framework/tests/json_results_update_tests.py
+++ b/framework/tests/json_results_update_tests.py
@@ -133,7 +133,7 @@ class TestV0toV1(object):
},
})
- with utils.with_tempfile(json.dumps(cls.DATA)) as t:
+ with utils.tempfile(json.dumps(cls.DATA)) as t:
with open(t, 'r') as f:
cls.RESULT = backends.json._update_zero_to_one(backends.json._load(f))
@@ -226,7 +226,7 @@ class TestV0toV1(object):
data = self.DATA
try:
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
result = backends.json.load_results(t)
except OSError as e:
# There is the potential that the file will be renamed. In that event
@@ -266,7 +266,7 @@ class TestV0toV1(object):
data['tests']['sometest']['info'] = \
'Returncode: 1\n\nErrors:stderr\n\nOutput: stdout\n\nmore\n\nstuff'
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
with open(t, 'r') as f:
backends.json._update_zero_to_one(backends.json._load(f))
@@ -310,7 +310,7 @@ class TestV2Update(object):
}
}
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
with open(t, 'r') as f:
cls.result = backends.json._update_one_to_two(
backends.json._load(f))
@@ -377,7 +377,7 @@ class TestV2NoUpdate(object):
}
}
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
with open(t, 'r') as f:
cls.result = backends.json._update_one_to_two(
backends.json._load(f))
@@ -453,7 +453,7 @@ class TestV2toV3(object):
}
}
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
with open(t, 'r') as f:
# pylint: disable=protected-access
cls.RESULT = backends.json._update_two_to_three(backends.json._load(f))
@@ -518,7 +518,7 @@ class TestV3toV4(object):
@staticmethod
def _make_result(data):
"""Write data to a file and return a result.TestrunResult object."""
- with utils.with_tempfile(json.dumps(data)) as t:
+ with utils.tempfile(json.dumps(data)) as t:
with open(t, 'r') as f:
# pylint: disable=protected-access
return backends.json._update_three_to_four(backends.json._load(f))
@@ -607,7 +607,7 @@ class TestV4toV5(object):
"has at windows",
]
- with utils.with_tempfile(json.dumps(cls.DATA)) as t:
+ with utils.tempfile(json.dumps(cls.DATA)) as t:
with open(t, 'r') as f:
cls.result = backends.json._update_four_to_five(backends.json._load(f))
diff --git a/framework/tests/shader_test_tests.py b/framework/tests/shader_test_tests.py
index 5844012..0ed5d80 100644
--- a/framework/tests/shader_test_tests.py
+++ b/framework/tests/shader_test_tests.py
@@ -38,7 +38,7 @@ def test_parse_gl_test_no_decimal():
"""test.shader_test.ShaderTest: raises if version lacks decminal"""
data = ('[require]\n'
'GL = 2\n')
- with utils.with_tempfile(data) as temp:
+ with utils.tempfile(data) as temp:
with nt.assert_raises(testm.ShaderTestParserException) as exc:
testm.ShaderTest(temp)
nt.assert_equal(exc.exception, "No GL version set",
@@ -52,7 +52,7 @@ def test_parse_gles2_test():
data = ('[require]\n'
'GL ES >= 2.0\n'
'GLSL ES >= 1.00\n')
- with utils.with_tempfile(data) as temp:
+ with utils.tempfile(data) as temp:
test = testm.ShaderTest(temp)
nt.assert_equal(
@@ -66,7 +66,7 @@ def test_parse_gles3_test():
data = ('[require]\n'
'GL ES >= 3.0\n'
'GLSL ES >= 3.00\n')
- with utils.with_tempfile(data) as temp:
+ with utils.tempfile(data) as temp:
test = testm.ShaderTest(temp)
nt.assert_equal(
diff --git a/framework/tests/summary_tests.py b/framework/tests/summary_tests.py
index 0bd34a0..0c9542d 100644
--- a/framework/tests/summary_tests.py
+++ b/framework/tests/summary_tests.py
@@ -74,8 +74,8 @@ def check_sets(old, ostat, new, nstat, set_):
old['tests']['sometest']['result'] = ostat
new['tests']['sometest']['result'] = nstat
- with utils.with_tempfile(json.dumps(old)) as ofile:
- with utils.with_tempfile(json.dumps(new)) as nfile:
+ with utils.tempfile(json.dumps(old)) as ofile:
+ with utils.tempfile(json.dumps(new)) as nfile:
summ = summary.Summary([ofile, nfile])
print(summ.tests)
@@ -95,7 +95,7 @@ class TestSubtestHandling(object):
data['tests']['with_subtests']['subtest']['subtest3'] = 'crash'
data['tests']['is_skip']['result'] = 'skip'
- with utils.with_tempfile(json.dumps(data)) as sumfile:
+ with utils.tempfile(json.dumps(data)) as sumfile:
cls.summ = summary.Summary([sumfile])
def test_subtests_are_tests(self):
diff --git a/framework/tests/utils.py b/framework/tests/utils.py
index 967204e..06c6796 100644
--- a/framework/tests/utils.py
+++ b/framework/tests/utils.py
@@ -29,7 +29,7 @@ from __future__ import print_function, absolute_import
import os
import sys
import shutil
-import tempfile
+import tempfile as tempfile_
import functools
import subprocess
from contextlib import contextmanager
@@ -44,7 +44,7 @@ from framework import test, backends, results
__all__ = [
- 'with_tempfile',
+ 'tempfile',
'resultfile',
'tempdir',
'JSON_DATA'
@@ -103,7 +103,7 @@ class StaticDirectory(object):
def setup_class(cls):
""" Create a temperary directory that will be removed in teardown_class
"""
- cls.tdir = tempfile.mkdtemp()
+ cls.tdir = tempfile_.mkdtemp()
@classmethod
def teardown_class(cls):
@@ -206,7 +206,7 @@ class GeneratedTestWrapper(object):
@contextmanager
def resultfile():
""" Create a stringio with some json in it and pass that as results """
- with tempfile.NamedTemporaryFile(delete=False) as output:
+ with tempfile_.NamedTemporaryFile(delete=False) as output:
json.dump(JSON_DATA, output)
yield output
@@ -215,7 +215,7 @@ def resultfile():
@contextmanager
-def with_tempfile(contents):
+def tempfile(contents):
""" Provides a context manager for a named tempfile
This contextmanager creates a named tempfile, writes data into that
@@ -228,7 +228,7 @@ def with_tempfile(contents):
"""
# Do not delete the tempfile as soon as it is closed
- temp = tempfile.NamedTemporaryFile(delete=False)
+ temp = tempfile_.NamedTemporaryFile(delete=False)
temp.write(contents)
temp.close()
@@ -240,7 +240,7 @@ def with_tempfile(contents):
@contextmanager
def tempdir():
""" Creates a temporary directory, returns it, and then deletes it """
- tdir = tempfile.mkdtemp()
+ tdir = tempfile_.mkdtemp()
yield tdir
shutil.rmtree(tdir)
--
2.3.5
More information about the Piglit
mailing list