Back to index

apport  2.4
Public Member Functions | Public Attributes
test_recoverable_problem.T Class Reference

List of all members.

Public Member Functions

def setUp
def wait_for_report
def call_recoverable_problem
def test_recoverable_problem
def test_invalid_data

Public Attributes

 report_dir
 datadir

Detailed Description

Definition at line 22 of file test_recoverable_problem.py.


Member Function Documentation

Definition at line 44 of file test_recoverable_problem.py.

00044 
00045     def call_recoverable_problem(self, data):
00046         cmd = ['%s/recoverable_problem' % self.datadir]
00047         proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
00048                                 stderr=subprocess.PIPE)
00049         err = proc.communicate(data.encode('UTF-8'))[1]
00050         if proc.returncode != 0:
00051             self.assertNotEqual(err, b'')  # we expect some error message
00052             raise subprocess.CalledProcessError(proc.returncode, cmd[0])
00053         self.assertEqual(err, b'')

Here is the caller graph for this function:

Definition at line 23 of file test_recoverable_problem.py.

00023 
00024     def setUp(self):
00025         self.report_dir = tempfile.mkdtemp()
00026         self.addCleanup(shutil.rmtree, self.report_dir)
00027         os.environ['APPORT_REPORT_DIR'] = self.report_dir
00028         self.datadir = os.environ.get('APPORT_DATA_DIR', '/usr/share/apport')

recoverable_problem with invalid data

Definition at line 65 of file test_recoverable_problem.py.

00065 
00066     def test_invalid_data(self):
00067         '''recoverable_problem with invalid data'''
00068 
00069         self.assertRaises(subprocess.CalledProcessError,
00070                           self.call_recoverable_problem, 'hello')
00071 
00072         self.assertRaises(subprocess.CalledProcessError,
00073                           self.call_recoverable_problem,
00074                           'hello\0there\0extraneous')
00075 
00076         self.assertRaises(subprocess.CalledProcessError,
00077                           self.call_recoverable_problem,
00078                           'hello\0\0there')
00079 
00080 
00081 unittest.main()

Here is the call graph for this function:

recoverable_problem with valid data

Definition at line 54 of file test_recoverable_problem.py.

00054 
00055     def test_recoverable_problem(self):
00056         '''recoverable_problem with valid data'''
00057 
00058         self.call_recoverable_problem('hello\0there')
00059         path = self.wait_for_report()
00060         with open(path, 'rb') as report_path:
00061             report = apport.report.Report()
00062             report.load(report_path)
00063             self.assertEqual(report['hello'], 'there')
00064             self.assertTrue('Pid:\t%d' % os.getpid() in report['ProcStatus'])

Here is the call graph for this function:

Definition at line 29 of file test_recoverable_problem.py.

00029 
00030     def wait_for_report(self):
00031         cwd = os.getcwd().replace('/', '_')
00032         base = sys.argv[0]
00033         if base.startswith('./'):
00034             base = base[2:]
00035         base = base.replace('/', '_')
00036         path = '%s_%s.%d.crash' % (cwd, base, os.getuid())
00037         path = os.path.join(self.report_dir, path)
00038         seconds = 0
00039         while not os.path.exists(path):
00040             time.sleep(1)
00041             seconds += 1
00042             self.assertTrue(seconds < 10, 'timeout while waiting for %s to be created.' % path)
00043         return path

Here is the caller graph for this function:


Member Data Documentation

Definition at line 27 of file test_recoverable_problem.py.

Definition at line 24 of file test_recoverable_problem.py.


The documentation for this class was generated from the following file: