mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
draft for path and path_list (#513)
* 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>
This commit is contained in:
63
tests/test_path_list.py
Normal file
63
tests/test_path_list.py
Normal file
@ -0,0 +1,63 @@
|
||||
import os
|
||||
import json
|
||||
import unittest
|
||||
from typing import Dict
|
||||
from jc.parsers.path_list 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_list--one': 'fixtures/generic/path_list--one',
|
||||
'path_list--two': 'fixtures/generic/path_list--two',
|
||||
'path_list--long': 'fixtures/generic/path_list--long',
|
||||
'path_list--windows': 'fixtures/generic/path_list--windows',
|
||||
'path_list--windows-long': 'fixtures/generic/path_list--windows-long',
|
||||
'path_list--windows-environment': 'fixtures/generic/path_list--windows-environment',
|
||||
'path_list--with-spaces': 'fixtures/generic/path_list--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()
|
Reference in New Issue
Block a user