mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
* draft for path_list * updaate doc * add input check * fix types * fix schema: add missing properties * add _process * fix _process docs * refactor: extract path.py parser * swap order of names alphabetically * documentation and comments * path parser: add early return for nodata * path and path-list parser: add test and fixtures * typo in file name * add early return for nodata * add test and fixtures * typo in file name * rename fixtures * rename fixtures * refactor to pathlib.Path * failing on windows - use PurePosixPath * changed the way to strip dot from suffix * add POSIX to path * test commit to see results on windows is failing * test commit to see results on windows is failing * add windows path detection * somehow Path not like the newline from input line * add test with more items * remove debug print * wrap test loops into into subTest * remove print statements * add path and path-list to CHANGELOG --------- Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
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)
|
|
|
|
|
|
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), {})
|
|
|
|
def test_path(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)
|
|
)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|