diff --git a/tests/conftest.py b/tests/conftest.py index 34a6528..22e14a1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,39 @@ import pytest from distutils.dir_util import copy_tree import natlink - +from functools import cache +import importlib +from shutil import copy as file_copy thisDir = Path(__file__).parent +@cache #only needs to be called once +def unimacro_source_dir() ->Path: + return Path(importlib.util.find_spec("unimacro").submodule_search_locations[0]) + +@cache +def unimacro_sample_ini_dir() ->Path: + return unimacro_source_dir()/"sample_ini" + + +def copy_grammar_ini(grammar_ini_file: str,unimacro_user_dir:Path): + + source_file=unimacro_sample_ini_dir()/"enx_inifiles"/grammar_ini_file + target_file=unimacro_user_dir / "enx_inifiles"/grammar_ini_file + return file_copy(source_file,target_file) + +#a function to build the fixture to copy a grammar ini file to unimacro user directory. see sample in test_brackets.py +#the fixture itself will return the same thing to the tests as the unimacro_setup fixture. + +def make_copy_grammar_ini_fixture(grammar_ini_file : str): + @pytest.fixture() + def grammar_ini_fixture(unimacro_setup): + copy_grammar_ini(grammar_ini_file,unimacro_setup[1]) + return unimacro_setup + return grammar_ini_fixture + + + + @pytest.fixture() def unimacro_setup(tmpdir): diff --git a/tests/test_brackets.py b/tests/test_brackets.py index 8f97c70..d0ceade 100644 --- a/tests/test_brackets.py +++ b/tests/test_brackets.py @@ -1,4 +1,28 @@ +import pytest +#boilerplate to copy the grammar ini file into the correct location +#just chagne grammar_ini to the name of the grammar ini file you want copied into +#unimacro user directory +grammar_ini= "_brackets.ini" +from conftest import make_copy_grammar_ini_fixture +#grammar_ini_fixture will depend on unimacro_setup, so you dont' need to specfiy unimacro_setup +#as a fixture in your tests. Though you can +grammar_ini_fixture=make_copy_grammar_ini_fixture(grammar_ini) +#end of boilderplate to copy the gramar ini file into correct location -#Add this to unimacro_userdirectory/enx_inifiles +#leave these first two samples in as documentation in test_brackets. confests docs say to look in this file for examples. +def test_sample_grammar_ini_fixture1(grammar_ini_fixture): + assert True -#C:\Users\doug\AppData\Local\Temp\pytest-of-doug\pytest-76\test_getTopOrChild0\unimacro_user_directory\enx_inifiles \ No newline at end of file +def test_sample_grammar_ini_fixture2(grammar_ini_fixture,unimacro_setup): + print(f"Unimacro setup sample: {unimacro_setup} grammar_ini_fixutre {grammar_ini_fixture} (should be the same)") + assert True + + +import sysconfig,sys +if __name__ == "__main__": + sysconfig._main() + print("This is your Python system path sys.path:") + print("-----------------------------------------") + print(sys.path) + + pytest.main([f'test_brackets.py']) \ No newline at end of file