5
5
import os .path
6
6
7
7
from omni_epd import displayfactory
8
- from pycasso .constants import PromptModeConst , PropertiesConst , ConfigConst , ProvidersConst
8
+ from pycasso .constants import PromptModeConst , PropertiesConst , ConfigConst , ProvidersConst , TestConst
9
9
from pycasso .pycasso import Pycasso
10
10
from PIL import Image , PngImagePlugin , ImageDraw
11
11
12
12
13
13
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 )
15
16
instance = Pycasso (config_path )
16
17
expected = 0
17
18
assert instance .args .savekeys == expected
18
19
19
20
20
21
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 )
22
24
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 )
25
26
expected = 160
26
27
assert config .opacity == expected
27
28
@@ -48,7 +49,7 @@ def test_display_image_on_epd():
48
49
49
50
50
51
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 )
52
53
tup = Pycasso .load_external_image (path , 400 , 400 )
53
54
pixel = tup [0 ].getpixel ((200 , 200 ))
54
55
expected = (158 , 142 , 138 )
@@ -57,7 +58,7 @@ def test_load_external_image():
57
58
58
59
59
60
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 )
61
62
tup = Pycasso .load_historic_image (path )
62
63
pixel = tup [0 ].getpixel ((200 , 200 ))
63
64
expected = (158 , 142 , 138 )
@@ -66,7 +67,7 @@ def test_load_historic_image_load_image():
66
67
67
68
68
69
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 )
70
71
tup = Pycasso .load_historic_image (path )
71
72
title = tup [1 ]
72
73
artist = tup [2 ]
@@ -78,7 +79,8 @@ def test_load_historic_image_load_metadata():
78
79
79
80
80
81
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 )
82
84
instance = Pycasso (config_path )
83
85
tup = instance .prep_prompt_text (PromptModeConst .PROMPT .value )
84
86
expected_prompt = "PreambleTest PromptPostscript"
@@ -96,8 +98,10 @@ def test_prep_subject_artist_prompt():
96
98
preamble = "Preamble"
97
99
connector = "Connector"
98
100
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 )
101
105
prompt , artist_text , title_text = Pycasso .prep_subject_artist_prompt (artist_path , subject_path , preamble , connector ,
102
106
postscript )
103
107
expected_prompt = "PreambleTest SubjectConnectorTest ArtistPostscript"
@@ -111,7 +115,8 @@ def test_prep_subject_artist_prompt():
111
115
def test_prep_normal_prompt ():
112
116
preamble = "Preamble"
113
117
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 )
115
120
prompt , title_text = Pycasso .prep_normal_prompt (prompt_path , preamble , postscript )
116
121
expected_prompt = "PreambleTest PromptPostscript"
117
122
expected_title = "Test Prompt"
@@ -121,7 +126,7 @@ def test_prep_normal_prompt():
121
126
122
127
123
128
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 )
125
130
save_path = os .path .join (dir_path ,
126
131
PropertiesConst .FILE_PREAMBLE .value + "TestPrompt." + ConfigConst .FILE_IMAGE_FORMAT .value )
127
132
img = Image .new (mode = "RGBA" , size = (600 , 400 ))
@@ -143,7 +148,8 @@ def test_save_image():
143
148
144
149
145
150
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 )
147
153
instance = Pycasso (config_path )
148
154
provider = instance .get_random_provider_mode ()
149
155
expected = [ProvidersConst .EXTERNAL .value , ProvidersConst .HISTORIC .value ]
@@ -153,7 +159,8 @@ def test_get_random_provider_mode():
153
159
def test_add_text_to_image ():
154
160
title_text = "TITLE"
155
161
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 )
157
164
img = Image .new (mode = "RGBA" , size = (600 , 400 ))
158
165
draw = ImageDraw .Draw (img , "RGBA" )
159
166
@@ -168,7 +175,8 @@ def test_add_text_to_image():
168
175
def test_add_text_to_image_blank ():
169
176
title_text = ""
170
177
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 )
172
180
img = Image .new (mode = "RGBA" , size = (600 , 400 ))
173
181
draw = ImageDraw .Draw (img , "RGBA" )
174
182
@@ -178,5 +186,3 @@ def test_add_text_to_image_blank():
178
186
expected = (0 , 0 , 0 , 0 )
179
187
180
188
assert pixel == expected
181
-
182
-
0 commit comments