Skip to content

Commit

Permalink
test with adding a grammar ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
dougransom committed Jan 6, 2023
1 parent f013fb6 commit fa3838a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
32 changes: 31 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
28 changes: 26 additions & 2 deletions tests/test_brackets.py
Original file line number Diff line number Diff line change
@@ -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
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'])

0 comments on commit fa3838a

Please sign in to comment.