File: test_htmllogger.py

package info (click to toggle)
simplemonitor 1.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,520 kB
  • sloc: python: 8,725; sh: 258; makefile: 74; javascript: 69
file content (50 lines) | stat: -rw-r--r-- 1,473 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# type: ignore
import os
import unittest

from simplemonitor.Loggers.file import HTMLLogger
from simplemonitor.Monitors.monitor import MonitorNull


class TestHTMLLogger(unittest.TestCase):
    def setUp(self):
        self._test_path = "test_html"
        try:
            os.mkdir(self._test_path)
        except FileExistsError:
            pass

    def test_html_logger(self):
        config_options = {
            "folder": "test_html",
            "copy_resources": True,
            "filename": "status.html",
        }
        test_logger = HTMLLogger(config_options)
        monitor = MonitorNull()
        monitor.run_test()
        test_logger.start_batch()
        test_logger.save_result2("test", monitor)
        test_logger.process_batch()
        test_logger.end_batch()

        self.assertTrue(
            os.path.exists(os.path.join("test_html", "status.html")),
            "status.html was not created",
        )
        self.assertTrue(
            os.path.exists(os.path.join("test_html", "main.bundle.js")),
            "main.bundle.js was not copied",
        )

    def tearDown(self):
        if os.path.isdir(self._test_path):
            for filename in os.listdir(self._test_path):
                try:
                    os.unlink(os.path.join(self._test_path, filename))
                except IOError:
                    pass
            try:
                os.rmdir(self._test_path)
            except IOError:
                pass