test_bag_to_html.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 Test: grep input bags to HTML output.
5 
6 ------------------------------------------------------------------------------
7 This file is part of grepros - grep for ROS bag files and live topics.
8 Released under the BSD License.
9 
10 @author Erki Suurjaak
11 @created 22.12.2021
12 @modified 25.12.2021
13 ------------------------------------------------------------------------------
14 """
15 import logging
16 import html.parser
17 import os
18 import sys
19 
20 sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
21 from test import testbase
22 
23 logger = logging.getLogger()
24 
25 
27  """Tests grepping from input bags and writing matches to HTML file."""
28 
29 
30  NAME = os.path.splitext(os.path.basename(__file__))[0]
31 
32 
33  OUTPUT_LABEL = "HTML"
34 
35 
36  OUTPUT_SUFFIX = ".html"
37 
38  def setUp(self):
39  """Collects bags in data directory, assembles command."""
40  super().setUp()
41  self._cmd = self.CMD_BASE + ["--no-console-output", "--write", self._outname]
42 
43  def test_grepros(self):
44  """Runs grepros on bags in data directory, verifies HTML output."""
45  self.verify_bags()
46  self.run_command()
47  self.assertTrue(os.path.isfile(self._outname), "Expected output file not written.")
48 
49  logger.info("Reading data from written %s.", self.OUTPUT_LABEL)
50  texts, parser = [], html.parser.HTMLParser()
51  parser.handle_data = texts.append
52  with open(self._outname) as f:
53  parser.feed(f.read())
54  fulltext = "".join(texts)
55  self.verify_topics(fulltext, fulltext)
56 
57 
58 if "__main__" == __name__:
59  TestBagInputHtmlOutput.run_rostest()
test.test_bag_to_html.TestBagInputHtmlOutput.OUTPUT_LABEL
string OUTPUT_LABEL
Name used in logging.
Definition: test_bag_to_html.py:33
test.testbase.TestBase
Definition: testbase.py:46
test.testbase.TestBase.CMD_BASE
list CMD_BASE
Base command for running grepros.
Definition: testbase.py:71
test.testbase.TestBase.verify_topics
def verify_topics(self, topics, messages=None)
Definition: testbase.py:176
test.test_bag_to_html.TestBagInputHtmlOutput.setUp
def setUp(self)
Definition: test_bag_to_html.py:38
test.testbase.TestBase._outname
_outname
Definition: testbase.py:97
test.test_bag_to_html.TestBagInputHtmlOutput._cmd
_cmd
Definition: test_bag_to_html.py:41
test.test_bag_to_html.TestBagInputHtmlOutput
Definition: test_bag_to_html.py:26
test.testbase.TestBase.verify_bags
def verify_bags(self)
Definition: testbase.py:169
test.testbase.TestBase.run_command
def run_command(self, communicate=True)
Definition: testbase.py:154
test.test_bag_to_html.TestBagInputHtmlOutput.test_grepros
def test_grepros(self)
Definition: test_bag_to_html.py:43


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:29