1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-21 00:19:42 +02:00

Feature: generic fixtures tests (#529)

* add generic test runners

* extract generic test runners

* beautify messages, remove unused return value

* add template and info do CONTRIBUTING

* typo

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
Muescha
2024-02-04 21:02:35 +01:00
committed by Kelly Brazil
parent d209780a9d
commit 962632ac1f
5 changed files with 117 additions and 91 deletions

View File

@ -1,59 +1,21 @@
import os
import json
import unittest
from typing import Dict
from jc.parsers.path import parse
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
FIXTURES_DIR = 'fixtures/generic/'
def open_file(name, ext):
return open(get_path(name, ext), 'r', encoding='utf-8')
def get_path(name, ext):
return os.path.join(THIS_DIR, name + '.' + ext)
from tests import utils_for_test as test_utils
class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}
fixtures = {
'path--one': 'fixtures/generic/path--one',
'path--long': 'fixtures/generic/path--long',
'path--windows': 'fixtures/generic/path--windows',
'path--with-spaces': 'fixtures/generic/path--with-spaces',
}
@classmethod
def setUpClass(cls):
for file, filepath in cls.fixtures.items():
with open_file(filepath, 'out') as in_file, \
open_file(filepath, 'json') as json_file:
cls.f_in[file] = in_file.read()
cls.f_json[file] = json.loads(json_file.read())
def test_path_nodata(self):
"""
Test 'path' with no data
"""
self.assertEqual(parse('', quiet=True), {})
test_utils.run_no_data(self, __file__, {})
def test_path(self):
def test_all_fixtures(self):
"""
Test 'path' with various logs
"""
for file in self.fixtures:
with self.subTest("fixture: " + file):
self.assertEqual(
parse(self.f_in[file], quiet=True),
self.f_json[file],
"Should be equal for test files: {0}.*".format(file)
)
test_utils.run_all_fixtures(self, __file__)
if __name__ == '__main__':