devops-exercises/tests/syntax_checker_unittest.py

45 lines
1.2 KiB
Python
Raw Normal View History

2019-12-21 19:24:54 +01:00
"""
WIP
2019-12-21 19:25:47 +01:00
Yes, we do write tests for our tests.
2019-12-21 19:24:54 +01:00
"""
2019-12-24 19:34:31 +01:00
from pathlib import Path
from typing import List
from unittest import TestCase
from tests import syntax_checker
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
def open_test_case_file(n: int) -> List[bytes]:
tests_path = Path(__file__).parent.joinpath()
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
with open(f'{tests_path}/testcases/testcase{n}.md', 'rb') as f:
file_list = [line.rstrip() for line in f.readlines()]
return file_list
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
test_case_1 = open_test_case_file(1)
test_case_2 = open_test_case_file(2)
test_case_3 = open_test_case_file(3)
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
class TestSyntax(TestCase):
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
def test_details_count_case1(self):
self.assertTrue(syntax_checker.count_details(test_case_1))
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
def test_details_count_case2(self):
self.assertTrue(syntax_checker.count_details(test_case_2))
2019-12-21 19:24:54 +01:00
2019-12-24 19:34:31 +01:00
def test_details_errors_1(self):
syntax_checker.check_details_tag(test_case_1)
self.assertFalse(syntax_checker.errors)
def test_details_errors_2(self):
syntax_checker.check_details_tag(test_case_2)
self.assertFalse(syntax_checker.errors)
#
# def test_details_error_exist_1(self):
# syntax_checker.check_details_tag(test_case_3)
# print(syntax_checker.errors)
# self.assertEqual(len(syntax_checker.errors), 3)