Skip to content

Commit 950be31

Browse files
committed
Add basic python library to allow easier access to the test data
1 parent 350a8ce commit 950be31

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include parser_tests/data/*.yaml

parser_tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = (0, 0, 1)

parser_tests/data.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
3+
import yaml
4+
5+
__all__ = (
6+
'mask_match', 'msg_join', 'msg_split',
7+
'userhost_split', 'validate_hostname',
8+
)
9+
10+
DATA_DIR = Path(__file__).resolve().parent / 'data'
11+
12+
13+
def load_data(name):
14+
with (DATA_DIR / '{}.yaml'.format(name)).open(encoding='utf-8') as f:
15+
data = yaml.safe_load(f)
16+
17+
return data
18+
19+
20+
mask_match = load_data('mask-match')
21+
msg_join = load_data('msg-join')
22+
msg_split = load_data('msg-split')
23+
userhost_split = load_data('userhost-split')
24+
validate_hostname = load_data('validate-hostname')

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyYaml

setup.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from contextlib import contextmanager
2+
from pathlib import Path
3+
4+
from setuptools import setup
5+
6+
import parser_tests
7+
8+
9+
@contextmanager
10+
def link_tests():
11+
"""
12+
Just a little bit of fuckery to symlink the data files in to the source tree
13+
"""
14+
data_files = Path('tests').resolve()
15+
src_dir = Path('parser_tests').resolve()
16+
src_data = (src_dir / 'data')
17+
src_data.symlink_to(data_files, True)
18+
yield
19+
src_data.unlink()
20+
21+
22+
with link_tests():
23+
setup(
24+
name="irc-parser-tests",
25+
# Generate the version string from __version__ tuple
26+
version='.'.join(map(str, parser_tests.__version__)),
27+
url='https://github.com/ircdocs/parser-tests',
28+
author="linuxdaemon",
29+
author_email="[email protected]",
30+
packages=['parser_tests'],
31+
install_requires=[
32+
'PyYaml',
33+
],
34+
include_package_data=True,
35+
)

0 commit comments

Comments
 (0)