Completed
Pull Request — master (#1847)
by Tushar
03:13 queued 01:33
created

tests.coalaHTMLTest.test_output_file()   B

Complexity

Conditions 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 24
rs 8.6845
1
import json
2
import os
3
import re
4
import sys
5
import unittest
6
7
from coalib import coala_html
8
from coalib.misc.ContextManagers import prepare_file
9
from tests.TestUtilities import execute_coala
10
from coalib.misc import Constants
11
12
ROOT = os.path.dirname(os.path.dirname(__file__))
13
14
15
class coalaHTMLTest(unittest.TestCase):
16
17
    def setUp(self):
18
        self.old_argv = sys.argv
19
        self.result_file = os.path.join(ROOT, 'coalib',
20
                                        Constants.CONFIGS['results_file'])
21
22
    def tearDown(self):
23
        sys.argv = self.old_argv
24
25
    def test_output_file(self):
26
        update_file = ""
27
        noupdate_file = ""
28
        with prepare_file(["#todo this is todo"], None) as (lines, filename):
29
            execute_coala(coala_html.main,
30
                          "coala-html",
31
                          "-c", os.devnull,
32
                          "-b", "LineCountBear",
33
                          "-f", re.escape(filename),
34
                          "--nolaunch")
35
            with open(self.result_file) as fp:
36
                update_file = json.load(fp)
37
            execute_coala(coala_html.main,
38
                          "coala-html",
39
                          "-c", os.devnull,
40
                          "-b", "LineCountBear",
41
                          "-f", re.escape(filename),
42
                          "-N",
43
                          "--nolaunch")
44
            with open(self.result_file) as fp:
45
                noupdate_file = json.load(fp)
46
47
        self.assertEqual(update_file['results']['default'][0]['message'],
48
                         noupdate_file['results']['default'][0]['message'])
49