def test_main(self): sys.argv = ["", "--init_pro"] create_dir(TEST_DATA_DIR) empty_dir(TEST_DATA_DIR) with InputMock(["Ich", "my-awesome-project", TEST_DATA_DIR]): emeki_main() shutil.rmtree(TEST_DATA_DIR)
def test_create_dir(self): dir_name = "Test_dir" try: create_dir(dir_name) assert os.path.isdir(dir_name) finally: os.removedirs(dir_name)
def test_user_project(self): target_dir = os.path.join(TEST_DATA_DIR, "project_test_data") create_dir(target_dir) with mock.patch("builtins.input", return_value="invalid_path"): assert not setup_project_UI() with InputMock([" ", " ", target_dir]): assert not setup_project_UI()
def test_project_creation_zip(self): target_dir = os.path.join(TEST_DATA_DIR, "project_test_data_zip") create_dir(target_dir) try: zip_template() setup_project_zipped(target_dir, "test-project", "emeki") finally: shutil.rmtree(target_dir)
def test_project_creation(self): target_dir = os.path.join(TEST_DATA_DIR, "project_test_data") create_dir(target_dir) try: setup_project(target_dir, "test-project", "emeki") finally: shutil.rmtree(target_dir)
def test_user_project_success(self): target_dir = os.path.join(TEST_DATA_DIR, "project_test_data") create_dir(target_dir) with open(os.path.join(target_dir, "hoi.txt"), "w") as f: f.write("hoi") with InputMock([" ", "project-name", target_dir, "blah"]): assert not setup_project_UI() with InputMock([" ", "project-name", target_dir, "n"]): assert not setup_project_UI() with InputMock([" ", "project-name", target_dir, "y"]): assert setup_project_UI()
def copy_and_modify_recursive(curr_path: str, curr_target_dir: str, rep_rule: Rule_T) -> None: """Copies a folder recursively and applies renaming.""" if os.path.isdir(curr_path): create_dir(curr_target_dir) for f in os.listdir(curr_path): f_path = os.path.join(curr_path, f) f_mod = repl_in_str(f, rep_rule) next_target_dir = os.path.join(curr_target_dir, f_mod) copy_and_modify_recursive(f_path, next_target_dir, rep_rule) else: if curr_path.split(".")[-1] in ALLOWED_EXT: print(curr_path) repl_in_file(curr_path, curr_target_dir, rep_rule)
from bs4 import BeautifulSoup from arcgis.geocoding import geocode from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, WebDriverException from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager from emeki.util import create_dir from arcgis.gis import GIS base_path = Path(__file__).parent CACHE_DIR = base_path / "cache" links_cache_dir = CACHE_DIR / "advert_links" info_cache_dir = CACHE_DIR / "advert_info" create_dir(CACHE_DIR) create_dir(links_cache_dir) create_dir(info_cache_dir) DriverType = webdriver.Chrome def cache_decorator(cache_dir: str, f_name: str): f_path = os.path.join(cache_dir, f_name) def cache_inner_decorator(fun): def new_fun(*args, **kwargs): if os.path.isfile(f_path): return pickle.load(open(f_path, "rb")) else: res = fun(*args, **kwargs)