Skip to content

Commit 84ebd53

Browse files
committed
Added constants for testing. Refactored folder locations to run tests from root. Moved pytest.ini back to root.
1 parent a723011 commit 84ebd53

File tree

6 files changed

+59
-34
lines changed

6 files changed

+59
-34
lines changed

pycasso/constants.py

+13
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ class DisplayShapeConst(Enum):
133133
CROSS = 1
134134
TRIANGLE = 2
135135
CIRCLE = 3
136+
137+
138+
class TestConst(Enum):
139+
TEST_FOLDER = "tests/"
140+
FILE_OPERATIONS_FOLDER = "test_file_operations_content"
141+
CONFIG_FILE = ".testconfig"
142+
CONFIG_FOLDER = "test_config_wrapper_content"
143+
TEMP_FOLDER = "test_temp"
144+
PYCASSO_FOLDER = "test_pycasso_content"
145+
ARTISTS_FILE = "artists.txt"
146+
SUBJECTS_FILE = "subjects.txt"
147+
PROMPTS_FILE = "prompts.txt"
148+
FONT_FILE = "Font.ttc"
File renamed without changes.

tests/test_config_wrapper.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55
import os
66
from pycasso.config_wrapper import Configs
7+
from pycasso.constants import TestConst
78

89

910
def test_init():
10-
config_path = os.path.join(os.getcwd(), 'test_config_wrapper_content/.testconfig')
11+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.CONFIG_FOLDER.value,
12+
TestConst.CONFIG_FILE.value)
1113
config = Configs(config_path)
14+
15+
assert config.add_text is False
1216
assert config.infill is False
1317

1418

1519
def test_read_config():
16-
config_path = os.path.join(os.getcwd(), 'test_config_wrapper_content/.testconfig')
20+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.CONFIG_FOLDER.value,
21+
TestConst.CONFIG_FILE.value)
1722
config = Configs(config_path)
1823
config.read_config()
1924

tests/test_file_operations.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import os
66
import collections
77
from pycasso.file_operations import FileOperations
8+
from pycasso.constants import TestConst
89

910

1011
def test_get_all_files():
11-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
12+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
1213
test_file = FileOperations(directory)
1314
result = test_file.get_all_files()
1415
expected = [os.path.join(directory, "lines.txt"),
@@ -19,7 +20,7 @@ def test_get_all_files():
1920

2021

2122
def test_get_all_files_of_type():
22-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
23+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
2324
test_file = FileOperations(directory)
2425
result = test_file.get_all_files_of_type("png")
2526
expected = os.path.join(directory, "test.png")
@@ -28,7 +29,7 @@ def test_get_all_files_of_type():
2829

2930

3031
def test_get_random_file():
31-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
32+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
3233
test_file = FileOperations(directory)
3334
result = test_file.get_random_file()
3435
expected = [os.path.join(directory, "lines.txt"),
@@ -38,7 +39,7 @@ def test_get_random_file():
3839

3940

4041
def test_get_random_file_of_type():
41-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
42+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
4243
test_file = FileOperations(directory)
4344
result = test_file.get_random_file_of_type("txt")
4445
expected = [os.path.join(directory, "lines.txt"),
@@ -73,23 +74,23 @@ def test_remove_text():
7374

7475

7576
def test_get_lines():
76-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
77+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
7778
path = os.path.join(directory, "lines.txt")
7879
result = FileOperations.get_lines(path)
7980
expected = ["first_line", "second_line", "third_line"]
8081
assert result == expected
8182

8283

8384
def test_get_random_line():
84-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
85+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
8586
path = os.path.join(directory, "lines.txt")
8687
result = FileOperations.get_random_line(path)
8788
expected = ["first_line", "second_line", "third_line"]
8889
assert result in expected
8990

9091

9192
def test_backup_file_both_exist():
92-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
93+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
9394
primary_path = os.path.join(directory, "lines.txt")
9495
backup_path = os.path.join(directory, "lines.txt")
9596
result = FileOperations.backup_file(primary_path, backup_path)
@@ -98,8 +99,8 @@ def test_backup_file_both_exist():
9899

99100

100101
def test_backup_file_no_primary():
101-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
102-
temp_directory = os.path.join(os.getcwd(), "test_temp")
102+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
103+
temp_directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.TEMP_FOLDER.value)
103104
primary_path = os.path.join(temp_directory, "new_file.txt")
104105
backup_path = os.path.join(directory, "lines.txt")
105106

@@ -118,7 +119,7 @@ def test_backup_file_no_primary():
118119

119120

120121
def test_backup_file_fail():
121-
temp_directory = os.path.join(os.getcwd(), "test_temp")
122+
temp_directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.TEMP_FOLDER.value)
122123
primary_path = os.path.join(temp_directory, "new_file.txt")
123124
backup_path = os.path.join(temp_directory, "non_existent.txt")
124125

@@ -140,7 +141,7 @@ def test_backup_file_fail():
140141

141142

142143
def test_get_full_path():
143-
directory = os.path.join(os.getcwd(), "test_file_operations_content")
144+
directory = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.FILE_OPERATIONS_FOLDER.value)
144145
test_file = FileOperations(directory)
145146
result = test_file.get_full_path("test.png")
146147
expected = os.path.join(directory, "test.png")

tests/test_pycasso.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
import os.path
66

77
from omni_epd import displayfactory
8-
from pycasso.constants import PromptModeConst, PropertiesConst, ConfigConst, ProvidersConst
8+
from pycasso.constants import PromptModeConst, PropertiesConst, ConfigConst, ProvidersConst, TestConst
99
from pycasso.pycasso import Pycasso
1010
from PIL import Image, PngImagePlugin, ImageDraw
1111

1212

1313
def test_parse_args():
14-
config_path = os.path.join(os.getcwd(), "test_pycasso_content", ".testconfig")
14+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
15+
TestConst.CONFIG_FILE.value)
1516
instance = Pycasso(config_path)
1617
expected = 0
1718
assert instance.args.savekeys == expected
1819

1920

2021
def test_load_config():
21-
config_path = os.path.join(os.getcwd(), "test_pycasso_content", ".testconfig")
22+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
23+
TestConst.CONFIG_FILE.value)
2224
instance = Pycasso(config_path)
23-
path = os.path.join(os.getcwd(), "test_pycasso_content", ".testconfig")
24-
config = instance.load_config(path)
25+
config = instance.load_config(config_path)
2526
expected = 160
2627
assert config.opacity == expected
2728

@@ -48,7 +49,7 @@ def test_display_image_on_epd():
4849

4950

5051
def test_load_external_image():
51-
path = os.path.join(os.getcwd(), "test_pycasso_content")
52+
path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value)
5253
tup = Pycasso.load_external_image(path, 400, 400)
5354
pixel = tup[0].getpixel((200, 200))
5455
expected = (158, 142, 138)
@@ -57,7 +58,7 @@ def test_load_external_image():
5758

5859

5960
def test_load_historic_image_load_image():
60-
path = os.path.join(os.getcwd(), "test_pycasso_content")
61+
path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value)
6162
tup = Pycasso.load_historic_image(path)
6263
pixel = tup[0].getpixel((200, 200))
6364
expected = (158, 142, 138)
@@ -66,7 +67,7 @@ def test_load_historic_image_load_image():
6667

6768

6869
def test_load_historic_image_load_metadata():
69-
path = os.path.join(os.getcwd(), "test_pycasso_content")
70+
path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value)
7071
tup = Pycasso.load_historic_image(path)
7172
title = tup[1]
7273
artist = tup[2]
@@ -78,7 +79,8 @@ def test_load_historic_image_load_metadata():
7879

7980

8081
def test_prep_prompt_text():
81-
config_path = os.path.join(os.getcwd(), "test_pycasso_content", ".testconfig")
82+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
83+
TestConst.CONFIG_FILE.value)
8284
instance = Pycasso(config_path)
8385
tup = instance.prep_prompt_text(PromptModeConst.PROMPT.value)
8486
expected_prompt = "PreambleTest PromptPostscript"
@@ -96,8 +98,10 @@ def test_prep_subject_artist_prompt():
9698
preamble = "Preamble"
9799
connector = "Connector"
98100
postscript = "Postscript"
99-
artist_path = os.path.join(os.getcwd(), "test_pycasso_content", "artists.txt")
100-
subject_path = os.path.join(os.getcwd(), "test_pycasso_content", "subjects.txt")
101+
artist_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
102+
TestConst.ARTISTS_FILE.value)
103+
subject_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
104+
TestConst.SUBJECTS_FILE.value)
101105
prompt, artist_text, title_text = Pycasso.prep_subject_artist_prompt(artist_path, subject_path, preamble, connector,
102106
postscript)
103107
expected_prompt = "PreambleTest SubjectConnectorTest ArtistPostscript"
@@ -111,7 +115,8 @@ def test_prep_subject_artist_prompt():
111115
def test_prep_normal_prompt():
112116
preamble = "Preamble"
113117
postscript = "Postscript"
114-
prompt_path = os.path.join(os.getcwd(), "test_pycasso_content", "prompts.txt")
118+
prompt_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
119+
TestConst.PROMPTS_FILE.value)
115120
prompt, title_text = Pycasso.prep_normal_prompt(prompt_path, preamble, postscript)
116121
expected_prompt = "PreambleTest PromptPostscript"
117122
expected_title = "Test Prompt"
@@ -121,7 +126,7 @@ def test_prep_normal_prompt():
121126

122127

123128
def test_save_image():
124-
dir_path = os.path.join(os.getcwd(), "test_temp")
129+
dir_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.TEMP_FOLDER.value)
125130
save_path = os.path.join(dir_path,
126131
PropertiesConst.FILE_PREAMBLE.value + "TestPrompt." + ConfigConst.FILE_IMAGE_FORMAT.value)
127132
img = Image.new(mode="RGBA", size=(600, 400))
@@ -143,7 +148,8 @@ def test_save_image():
143148

144149

145150
def test_get_random_provider_mode():
146-
config_path = os.path.join(os.getcwd(), "test_pycasso_content", ".testconfig")
151+
config_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
152+
TestConst.CONFIG_FILE.value)
147153
instance = Pycasso(config_path)
148154
provider = instance.get_random_provider_mode()
149155
expected = [ProvidersConst.EXTERNAL.value, ProvidersConst.HISTORIC.value]
@@ -153,7 +159,8 @@ def test_get_random_provider_mode():
153159
def test_add_text_to_image():
154160
title_text = "TITLE"
155161
artist_text = "ARTIST"
156-
font_path = os.path.join(os.getcwd(), "test_pycasso_content", "Font.ttc")
162+
font_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
163+
TestConst.FONT_FILE.value)
157164
img = Image.new(mode="RGBA", size=(600, 400))
158165
draw = ImageDraw.Draw(img, "RGBA")
159166

@@ -168,7 +175,8 @@ def test_add_text_to_image():
168175
def test_add_text_to_image_blank():
169176
title_text = ""
170177
artist_text = ""
171-
font_path = os.path.join(os.getcwd(), "test_pycasso_content", "Font.ttc")
178+
font_path = os.path.join(os.getcwd(), TestConst.TEST_FOLDER.value, TestConst.PYCASSO_FOLDER.value,
179+
TestConst.FONT_FILE.value)
172180
img = Image.new(mode="RGBA", size=(600, 400))
173181
draw = ImageDraw.Draw(img, "RGBA")
174182

@@ -178,5 +186,3 @@ def test_add_text_to_image_blank():
178186
expected = (0, 0, 0, 0)
179187

180188
assert pixel == expected
181-
182-

tests/test_pycasso_content/.testconfig

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
save_image=False
44
image_format=jpg
5-
subjects_file=test_pycasso_content/subjects.txt
6-
artists_file=test_pycasso_content/artists.txt
7-
prompts_file=test_pycasso_content/prompts.txt
5+
subjects_file=tests/test_pycasso_content/subjects.txt
6+
artists_file=tests/test_pycasso_content/artists.txt
7+
prompts_file=tests/test_pycasso_content/prompts.txt
88

99
[Prompt]
1010

0 commit comments

Comments
 (0)