37 PKG =
'diagnostic_analysis' 39 import roslib; roslib.load_manifest(PKG)
44 from diagnostic_msgs.msg
import DiagnosticArray, DiagnosticStatus, KeyValue
58 array = DiagnosticArray()
59 stat = DiagnosticStatus()
62 stat.name =
'Unit Test' 63 stat.hardware_id =
'HW ID' 65 KeyValue(
'Value A', str(count)),
66 KeyValue(
'Value B', str(count)),
67 KeyValue(
'Value C', str(count))]
68 array.status = [ stat ]
75 self.
bag = tempfile.NamedTemporaryFile()
78 for i
in range(0, row_count):
84 self.exp.process_log()
85 self.exp.finish_logfile()
86 self.
filename = self.exp.get_filename(
'Unit Test')
94 self.assert_(self.
filename is not None,
"CSV file is None")
95 self.assert_(os.path.isfile(self.
filename),
"CSV file doesn't exist")
100 input_reader = csv.reader(open(self.
filename,
'rb'))
102 for row
in input_reader:
104 self.assert_(row[2].strip() ==
'Message')
105 self.assert_(row[3].strip() ==
'Hardware ID')
106 self.assert_(row[4].strip() ==
'Value A')
110 self.assert_(row[2].strip() ==
'OK')
111 self.assert_(row[3].strip() ==
'HW ID')
112 self.assert_(row[4].strip() == str(count))
115 self.assert_(count == row_count,
"Row count doesn't match")
119 self.assert_(len(open(self.
skip_10).read().split(
'\n')) <= int(row_count / 10) + 2,
"Length of sparse CSV (skipped) incorrect")
123 self.assert_(len(open(self.
length_10).read().split(
'\n')) == 12,
"Length of sparse CSV incorrect")
130 self.exp.remove_files()
133 if __name__ ==
'__main__':
135 rostest.unitrun(PKG,
'bag_csv_test', TestBagToCSV)
138 suite = unittest.TestSuite()
144 unittest.TextTestRunner(verbosity = 2).run(suite)
Tests convert logfile to CSV and making sparse.
def test_sparse_length(self)
Tests that sparse CSV made with 'length' option has correct number of lines.
def test_file_exists(self)
Tests that exported file exists and is not None.
def test_sparse_skip(self)
Tests that sparse CSV made with 'skip' option has correct number of lines.
def test_export(self)
Test that CSV file has correct data, number of lines.
def make_status_msg(count)
Make DiagnosticArray message for testing.
Converts and processes diagnostics logs to CSV format.
def make_sparse_length(csv_file, length)
Makes sparse CSV with the given number of rows.
def make_sparse_skip(csv_file, skip)
Makes sparse CSV by skipping every nth value.
skip_10
Make sparse CSV's.