11"""Unit test package for gramps_webapi."""
22
33import gzip
4- import importlib
54import os
65import shutil
76import tempfile
87import unittest
9- from typing import Optional
108
11- import gramps .cli .clidbman
12- import gramps .cli .grampscli
9+ TEST_GRAMPSHOME = tempfile .mkdtemp ()
10+ os .environ ["GRAMPSHOME" ] = TEST_GRAMPSHOME
11+
12+ from gramps .cli .clidbman import CLIDbManager
13+ from gramps .cli .grampscli import CLIManager
1314from gramps .gen .config import get as getconfig
1415from gramps .gen .config import set as setconfig
16+ from gramps .gen .const import USER_DIRLIST
1517from gramps .gen .db .base import DbReadBase
1618from gramps .gen .db .utils import import_as_dict , make_database
1719from gramps .gen .dbstate import DbState
@@ -26,6 +28,8 @@ class ExampleDbBase:
2628
2729 def __init__ (self ) -> None :
2830 """Initialize self."""
31+ for path in USER_DIRLIST :
32+ os .makedirs (path , exist_ok = True )
2933 _resources = ResourcePath ()
3034 doc_dir = _resources .doc_dir
3135 self .path = os .path .join (doc_dir , "example" , "gramps" , "example.gramps" )
@@ -43,8 +47,6 @@ def __init__(self) -> None:
4347 " found at {}" .format (os .path .dirname (self .path_gz ))
4448 )
4549 self .path = self ._extract_to_tempfile ()
46- self .tmp_dbdir = None
47- self .old_path = None
4850
4951 def _extract_to_tempfile (self ) -> str :
5052 """Extract the example DB to a temp file and return the path."""
@@ -88,25 +90,17 @@ class ExampleDbSQLite(ExampleDbBase, WebDbManager):
8890 app = create_app(db_manager = exampledb)
8991 ```
9092
91- Instantiation should occur during test fixture setup, at which
92- point GRAMPSHOME should have been set and the temporary Gramps
93- user directory structure created. The database will be imported
94- under there, and when testing is done the test fixture teardown
95- is responsible for cleanup.
93+ Instantiation should occur during test fixture setup, which should
94+ insure the temporary Gramps user directory structure was created.
95+ The database will be imported under there, and when testing is done
96+ the test fixture teardown is responsible for cleanup.
9697 """
9798
9899 def __init__ (self , name : str = None ) -> None :
99100 """Prepare and import the example DB."""
100- importlib .reload (gramps .cli .clidbman )
101- from gramps .cli .clidbman import CLIDbManager
102-
103- importlib .reload (gramps .cli .grampscli )
104- from gramps .cli .grampscli import CLIManager
105-
106101 ExampleDbBase .__init__ (self )
107102 self .db_path = os .path .join (os .environ ["GRAMPSHOME" ], "gramps" , "grampsdb" )
108- if not os .path .isdir (self .db_path ):
109- os .makedirs (self .db_path )
103+ os .makedirs (self .db_path , exist_ok = True )
110104 setconfig ("database.path" , self .db_path )
111105 dbstate = DbState ()
112106 dbman = CLIDbManager (dbstate )
0 commit comments