Skip to content

Commit 8503cce

Browse files
committed
Tests now check message details
1 parent 84954e5 commit 8503cce

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/test_morphapp.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,43 @@ def test_parser_numerical(self, setup_parser):
105105
) # Check correct value parsed
106106
assert len(n_args) == 1 # Check one leftover
107107

108-
def test_parser_systemexits(self, setup_parser):
108+
def test_parser_systemexits(self, capsys, setup_parser):
109109
# ###Basic tests for any variety of morphing###
110110

111111
# Ensure only two pargs given for morphing
112112
(opts, pargs) = self.parser.parse_args(["toofewfiles"])
113113
with pytest.raises(SystemExit):
114114
single_morph(self.parser, opts, pargs, stdout_flag=False)
115+
_, err = capsys.readouterr()
116+
assert "You must supply FILE1 and FILE2." in err
115117
with pytest.raises(SystemExit):
116118
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
119+
_, err = capsys.readouterr()
120+
assert "You must supply FILE and DIRECTORY." in err
117121
(opts, pargs) = self.parser.parse_args(["too", "many", "files"])
118122
with pytest.raises(SystemExit):
119123
single_morph(self.parser, opts, pargs, stdout_flag=False)
124+
_, err = capsys.readouterr()
125+
assert (
126+
"Too many arguments. Make sure you only supply FILE1 and FILE2."
127+
in err
128+
)
120129
with pytest.raises(SystemExit):
121130
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
131+
_, err = capsys.readouterr()
132+
assert (
133+
"Too many arguments. You must only supply a FILE and a DIRECTORY."
134+
in err
135+
)
122136

123137
# Make sure rmax greater than rmin
124138
(opts, pargs) = self.parser.parse_args(
125139
[f"{nickel_PDF}", f"{nickel_PDF}", "--rmin", "10", "--rmax", "1"]
126140
)
127141
with pytest.raises(SystemExit):
128142
single_morph(self.parser, opts, pargs, stdout_flag=False)
143+
_, err = capsys.readouterr()
144+
assert "rmin must be less than rmax" in err
129145

130146
# ###Tests exclusive to multiple morphs###
131147
# Make sure we save to a directory that exists
@@ -140,8 +156,12 @@ def test_parser_systemexits(self, setup_parser):
140156
)
141157
with pytest.raises(SystemExit):
142158
single_morph(self.parser, opts, pargs, stdout_flag=False)
159+
_, err = capsys.readouterr()
160+
assert "Unable to save to designated location." in err
143161
with pytest.raises(SystemExit):
144162
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
163+
_, err = capsys.readouterr()
164+
assert "is not a directory." in err
145165

146166
# Ensure first parg is a FILE and second parg is a DIRECTORY
147167
(opts, pargs) = self.parser.parse_args(
@@ -152,15 +172,21 @@ def test_parser_systemexits(self, setup_parser):
152172
(opts, pargs) = self.parser.parse_args(
153173
[f"{testsequence_dir}", f"{testsequence_dir}"]
154174
)
175+
_, err = capsys.readouterr()
176+
assert "is not a directory." in err
155177
with pytest.raises(SystemExit):
156178
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
179+
_, err = capsys.readouterr()
180+
assert "is not a file." in err
157181

158182
# Try sorting by non-existing field
159183
(opts, pargs) = self.parser.parse_args(
160184
[f"{nickel_PDF}", f"{testsequence_dir}", "--sort-by", "fake_field"]
161185
)
162186
with pytest.raises(SystemExit):
163187
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
188+
_, err = capsys.readouterr()
189+
assert "The requested field is missing from a PDF file header." in err
164190
(opts, pargs) = self.parser.parse_args(
165191
[
166192
f"{nickel_PDF}",
@@ -173,6 +199,8 @@ def test_parser_systemexits(self, setup_parser):
173199
)
174200
with pytest.raises(SystemExit):
175201
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
202+
_, err = capsys.readouterr()
203+
assert "The requested field was not found in the metadata file." in err
176204

177205
# Try plotting an unknown parameter
178206
(opts, pargs) = self.parser.parse_args(
@@ -185,6 +213,8 @@ def test_parser_systemexits(self, setup_parser):
185213
)
186214
with pytest.raises(SystemExit):
187215
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
216+
_, err = capsys.readouterr()
217+
assert "Cannot find specified plot parameter. No plot shown." in err
188218

189219
# Try plotting an unrefined parameter
190220
(opts, pargs) = self.parser.parse_args(
@@ -197,6 +227,12 @@ def test_parser_systemexits(self, setup_parser):
197227
)
198228
with pytest.raises(SystemExit):
199229
multiple_targets(self.parser, opts, pargs, stdout_flag=False)
230+
_, err = capsys.readouterr()
231+
assert (
232+
"The plot parameter is missing values for at "
233+
"least one morph and target pair. "
234+
"No plot shown." in err
235+
)
200236

201237
# Pass a non-float list to squeeze
202238
(opts, pargs) = self.parser.parse_args(
@@ -209,6 +245,8 @@ def test_parser_systemexits(self, setup_parser):
209245
)
210246
with pytest.raises(SystemExit):
211247
single_morph(self.parser, opts, pargs, stdout_flag=False)
248+
_, err = capsys.readouterr()
249+
assert "a could not be converted to float." in err
212250

213251
def test_morphsequence(self, setup_morphsequence):
214252
# Parse arguments sorting by field

0 commit comments

Comments
 (0)