fix unittest / CLI import
This commit is contained in:
@@ -32,7 +32,6 @@ from .sections import (
|
||||
|
||||
from .simpleini import PySimpleINI
|
||||
|
||||
from .__main__ import CLI
|
||||
|
||||
try: # pragma: no cover
|
||||
__version__ = version("pysimpleini")
|
||||
@@ -53,3 +52,5 @@ try: # pragma: no cover
|
||||
except PackageNotFoundError: # pragma: no cover
|
||||
warnings.warn('can not read dist.metadata["Name"], assuming local test context, setting it to <pysimpleini>')
|
||||
__Name__ = "pysimpleini"
|
||||
|
||||
from .__main__ import CLI
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
from io import StringIO
|
||||
from contextlib import redirect_stdout,redirect_stderr
|
||||
|
||||
from src.pysimpleini import __main__ as pysimpleini__main__
|
||||
from src.pysimpleini import CLI
|
||||
|
||||
|
||||
testdir_path = Path(__file__).parent.resolve()
|
||||
@@ -37,7 +37,7 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
with mock.patch("sys.argv" , \
|
||||
["-f",ofile,\
|
||||
"setaddkeyvalue","testsection","NewKey","NewValue"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
|
||||
# 3/ Check if original file wasn't modified
|
||||
self._test_read_file_gen(str(testdir_path / "testfiles/test_simpleread.ini"))
|
||||
@@ -46,7 +46,7 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",ofile,"getallkeynames","testsection"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual( \
|
||||
["key1",\
|
||||
@@ -60,7 +60,7 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",ofile,"getkeyvalue","testsection","NewKey"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["NewValue"], stdout.split())
|
||||
|
||||
@@ -78,14 +78,14 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
["-f",src_filepath,\
|
||||
"-of",dst_filepath,\
|
||||
"rewrite"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
|
||||
def _test_read_file_gen(self,filepath:str):
|
||||
# 1/ Check if section is present
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getallsectionnames"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["testsection"], stdout.split())
|
||||
|
||||
@@ -93,7 +93,7 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getallkeynames","testsection"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual( \
|
||||
["key1",\
|
||||
@@ -106,27 +106,27 @@ class Test_PySimpleINI_ArgParse(unittest.TestCase):
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getkeyvalue","testsection","key1"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["test"], stdout.split())
|
||||
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getkeyvalue","testsection","key2"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["2"], stdout.split())
|
||||
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getkeyvalue","testsection","key3"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["43"], stdout.split())
|
||||
|
||||
with redirect_stdout(StringIO()) as capted_stdout, \
|
||||
mock.patch("sys.argv" , \
|
||||
["-f",filepath,"getkeyvalue","testsection","key4"]):
|
||||
pysimpleini__main__.CLI()
|
||||
CLI()
|
||||
stdout=capted_stdout.getvalue()
|
||||
self.assertEqual(["0.54"], stdout.split())
|
||||
Reference in New Issue
Block a user