[SATYR PATCHv2 4/6] tests: refactor input file loading into common function
Martin Milata
mmilata at redhat.com
Mon Jun 24 09:30:09 UTC 2013
Signed-off-by: Martin Milata <mmilata at redhat.com>
---
tests/python/gdb.py | 12 ++----------
tests/python/java.py | 11 ++---------
tests/python/koops.py | 17 +++--------------
tests/python/python.py | 15 +++------------
tests/python/test_helpers.py | 8 ++++++++
5 files changed, 18 insertions(+), 45 deletions(-)
diff --git a/tests/python/gdb.py b/tests/python/gdb.py
index e192a22..6e57c17 100755
--- a/tests/python/gdb.py
+++ b/tests/python/gdb.py
@@ -1,8 +1,7 @@
#!/usr/bin/env python
-import os
import unittest
-from test_helpers import BindingsTestCase
+from test_helpers import BindingsTestCase, load_input_contents
try:
import _satyr as satyr
@@ -10,7 +9,7 @@ except ImportError:
import satyr
-path = '../gdb_stacktraces/rhbz-803600'
+contents = load_input_contents('../gdb_stacktraces/rhbz-803600')
threads_expected = 2
frames_expected = 227
expected_short_text = '''Thread no. 1 (5 frames)
@@ -21,13 +20,6 @@ expected_short_text = '''Thread no. 1 (5 frames)
#4 _gtk_marshal_BOOLEAN__BOXED at gtkmarshalers.c
'''
-
-if not os.path.isfile(path):
- path = '../' + path
-
-with file(path) as f:
- contents = f.read()
-
class TestGdbStacktrace(BindingsTestCase):
def setUp(self):
self.trace = satyr.GdbStacktrace(contents)
diff --git a/tests/python/java.py b/tests/python/java.py
index 7b4685e..1c7fc5f 100755
--- a/tests/python/java.py
+++ b/tests/python/java.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
-import os
import unittest
-from test_helpers import BindingsTestCase
+from test_helpers import BindingsTestCase, load_input_contents
try:
import _satyr as satyr
except ImportError:
import satyr
-path = '../java_stacktraces/java-02'
+contents = load_input_contents('../java_stacktraces/java-02')
threads_expected = 1
frames_expected = 32
expected_short_text = '''#1 org.hibernate.exception.ConstraintViolationException: could not insert: [com.example.myproject.MyEntity]
@@ -22,12 +21,6 @@ expected_short_text = '''#1 org.hibernate.exception.ConstraintViolationException
#8 \tat javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [unknown]
'''
-if not os.path.isfile(path):
- path = '../' + path
-
-with file(path) as f:
- contents = f.read()
-
class TestJavaStacktrace(BindingsTestCase):
def setUp(self):
self.trace = satyr.JavaStacktrace(contents)
diff --git a/tests/python/koops.py b/tests/python/koops.py
index 58189c8..81e67b9 100755
--- a/tests/python/koops.py
+++ b/tests/python/koops.py
@@ -1,15 +1,14 @@
#!/usr/bin/env python
-import os
import unittest
-from test_helpers import BindingsTestCase
+from test_helpers import BindingsTestCase, load_input_contents
try:
import _satyr as satyr
except ImportError:
import satyr
-path = '../kerneloopses/rhbz-827868'
+contents = load_input_contents('../kerneloopses/rhbz-827868')
frames_expected = 32
mods_expected = 119
expected_short_text = '''#1 warn_slowpath_common
@@ -21,12 +20,6 @@ expected_short_text = '''#1 warn_slowpath_common
#7 __get_free_pages
'''
-if not os.path.isfile(path):
- path = '../' + path
-
-with file(path) as f:
- contents = f.read()
-
class TestKerneloops(BindingsTestCase):
def setUp(self):
self.koops = satyr.Kerneloops(contents)
@@ -44,11 +37,7 @@ class TestKerneloops(BindingsTestCase):
def test_correct_taint_flags(self):
for val in self.koops.taint_flags.values():
self.assertFalse(val);
- path = '../kerneloopses/rhbz-827868-modified'
- if not os.path.isfile(path):
- path = '../' + path
- with file(path) as f:
- contents = f.read()
+ contents = load_input_contents('../kerneloopses/rhbz-827868-modified')
tainted_koops = satyr.Kerneloops(contents)
true_flags = { f for (f, v) in tainted_koops.taint_flags.items() if v == True}
diff --git a/tests/python/python.py b/tests/python/python.py
index 1209617..1ae36eb 100755
--- a/tests/python/python.py
+++ b/tests/python/python.py
@@ -1,9 +1,8 @@
#!/usr/bin/env python
-import os
import unittest
-from test_helpers import BindingsTestCase
+from test_helpers import BindingsTestCase, load_input_contents
try:
import _satyr as satyr
@@ -11,6 +10,7 @@ except ImportError:
import satyr
path = '../python_stacktraces/python-01'
+contents = load_input_contents(path)
frames_expected = 11
expected_short_text = '''#1 _getPackage in /usr/share/PackageKit/helpers/yum/yumBackend.py:2534
#2 updateProgress in /usr/share/PackageKit/helpers/yum/yumBackend.py:2593
@@ -20,12 +20,6 @@ expected_short_text = '''#1 _getPackage in /usr/share/PackageKit/helpers/yum/yum
#6 predownload_hook in /usr/lib/yum-plugins/presto.py:577
'''
-if not os.path.isfile(path):
- path = '../' + path
-
-with file(path) as f:
- contents = f.read()
-
class TestPythonStacktrace(BindingsTestCase):
def setUp(self):
self.trace = satyr.PythonStacktrace(contents)
@@ -60,10 +54,7 @@ class TestPythonStacktrace(BindingsTestCase):
self.assertGetSetCorrect(self.trace, 'exception_name', 'AttributeError', 'WhateverException')
def test_special_files_and_frames(self):
- path2 = str(path)
- path2 = path2[0:-1] + '3'
- with open(path2, 'r') as f:
- trace = f.read()
+ trace = load_input_contents('../python_stacktraces/python-03')
trace = satyr.PythonStacktrace(trace)
f = trace.frames[0]
diff --git a/tests/python/test_helpers.py b/tests/python/test_helpers.py
index e8de55d..ba023a0 100644
--- a/tests/python/test_helpers.py
+++ b/tests/python/test_helpers.py
@@ -1,3 +1,4 @@
+import os
import unittest
class BindingsTestCase(unittest.TestCase):
@@ -10,6 +11,13 @@ class BindingsTestCase(unittest.TestCase):
self.assertEqual(obj.__getattribute__(attr), new_val)
self.assertRaises(TypeError, obj.__delattr__, attr)
+def load_input_contents(path):
+ if not os.path.isfile(path):
+ path = '../' + path
+
+ with file(path) as f:
+ return f.read()
+
if __name__ == '__main__':
import sys
sys.exit('This module is not meant to be run directly')
--
1.7.11.7
More information about the Crash-catcher
mailing list