Skip to content

Commit

Permalink
Fix pytest
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Sep 8, 2023
1 parent 60e181e commit cc34b37
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions test/test_fypp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
'''Unit tests for testing Fypp.'''
from contextlib import contextmanager
from os import getcwd, chdir
from pathlib import Path
import platform
import unittest
import fypp.fypp as fypp
from fypp.cli import get_option_parser

DIR = Path(__file__).parent.resolve()
BASE = DIR.parent


@contextmanager
def cd(target):
"""
Manage cd in a pushd/popd fashion.
Usage:
with cd(tmpdir):
do something in tmpdir
"""
curdir = getcwd()
chdir(target)
try:
yield
finally:
chdir(curdir)


def _linenum(linenr, fname=None, flag=None):
if fname is None:
Expand Down Expand Up @@ -1413,7 +1436,7 @@ def _importmodule(module):
),
('escape_comment',
([],
'A\n #\! Comment\n',
'A\n #\\! Comment\n',
'A\n #! Comment\n',
)
),
Expand Down Expand Up @@ -2151,8 +2174,8 @@ def _importmodule(module):
)
),
('file_var_root_abs',
([f"--file-var-root={Path.cwd()}"],
f"{Path.cwd() / 'input/filevarroot.fypp'}",
([f"--file-var-root={DIR}"],
f"{DIR / 'input/filevarroot.fypp'}",
'FILE: input/filevarroot.fypp:1\n'
'THIS_FILE: input/filevarroot.fypp:2\n'
'---\n'
Expand Down Expand Up @@ -2961,8 +2984,10 @@ def test_output(self):
parser = get_option_parser()
options, leftover = parser.parse_known_args(args)
self.assertEqual(len(leftover), 0)
tool = fypp.Fypp(options)
result = tool.process_text(inp)
# TODO: Use proper test fixture to temporary folder
with cd(DIR):
tool = fypp.Fypp(options)
result = tool.process_text(inp)
self.assertEqual(out, result)
return test_output

Expand All @@ -2984,8 +3009,10 @@ def test_output_from_file_input(self):
parser = get_option_parser()
options, leftover = parser.parse_known_args(args)
self.assertEqual(len(leftover), 0)
tool = fypp.Fypp(options)
result = tool.process_file(inputfile)
# TODO: Use proper test fixture to temporary folder
with cd(DIR):
tool = fypp.Fypp(options)
result = tool.process_file(inputfile)
self.assertEqual(out, result)
return test_output_from_file_input

Expand All @@ -3011,8 +3038,10 @@ def test_exception(self):
options, leftover = parser.parse_known_args(args)
self.assertEqual(len(leftover), 0)
try:
tool = fypp.Fypp(options)
_ = tool.process_text(inp)
# TODO: Use proper test fixture to temporary folder
with cd(DIR):
tool = fypp.Fypp(options)
_ = tool.process_text(inp)
except Exception as e:
raised = e
else:
Expand Down

0 comments on commit cc34b37

Please sign in to comment.