-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
107 lines (83 loc) · 2.65 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import shutil
import subprocess
import time
from typing import Dict, List, Union
import pytest
from src.zet.git_commands import git_add_zets, git_init_zets
from src.zet.repo import Repo
from src.zet.settings import Settings
from src.zet.zet import Zet
@pytest.fixture(scope="module")
def zet_settings(pytestconfig) -> Settings:
"""Test setup and teardown.
All functions need to import this fixture.
The settings are created and torn down properly
for each test that has this as a fixture.
"""
# Setup
# creates local settings
settings = Settings()
repo = Repo()
repo.add_repo("zets")
yield settings.refresh() # default repo name returned for subsequent invocations
# Teardown
scratch_repo_one = "other/"
workspace = pytestconfig.rootdir / "~"
if workspace.exists():
shutil.rmtree(workspace)
if settings.install_path.exists():
shutil.rmtree(settings.install_path)
if os.path.exists(scratch_repo_one):
shutil.rmtree(scratch_repo_one)
@pytest.fixture
def zet(zet_settings: Settings) -> str:
sample_zet = Zet()
sample_zet.create(
title="some title",
category="some category",
tags="some, tags",
zet_repo=zet_settings.get_default_repo(),
)
return sample_zet.path
@pytest.fixture
def zet_list(zet_settings: Settings) -> List[str]:
for i in range(5):
time.sleep(1)
Zet().create(
"some title",
"some category",
"some, tags",
zet_settings.get_default_repo()
)
repos = Repo()
sample_zets = repos.list_zets()
return sample_zets
@pytest.fixture
def zet_list_paths(zet_settings: Settings) -> List[str]:
for i in range(5):
time.sleep(1)
Zet().create(
"some title",
"some category",
"some, tags",
zet_settings.get_default_repo()
)
repo = Repo()
sample_zets = repo.list_zets(full_path=True)
return sample_zets
@pytest.fixture
def zet_git_repo(zet_settings: Settings) -> Union[None, Dict]:
try:
git_init_zets(zet_settings.get_default_repo())
except subprocess.CalledProcessError as error:
error_dict = {"response_code": error.returncode, "output": error.output}
return error_dict
@pytest.fixture
def zet_git_repo_changes(zet_settings: Settings, zet_git_repo) -> str:
repo_path = zet_settings.get_default_repo_path()
new_file_path = os.path.join(repo_path, "some_file.md")
new_file = open(new_file_path, "w")
new_file.writelines(["some text", "some other text"])
new_file.close()
git_add_zets(zet_settings.get_default_repo())