comparison env/lib/python3.9/site-packages/galaxy/tool_util/verify/asserts/text.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import re
2
3
4 def assert_has_text(output, text, n=None):
5 """ Asserts specified output contains the substring specified by
6 the argument text. The exact number of occurrences can be
7 optionally specified by the argument n."""
8 if n is None:
9 assert output.find(text) >= 0, f"Output file did not contain expected text '{text}' (output '{output}')"
10 else:
11 matches = re.findall(re.escape(text), output)
12 assert len(matches) == int(n), "Expected {} matches for '{}' in output file (output '{}'); found {}".format(n, text, output, len(matches))
13
14
15 def assert_not_has_text(output, text):
16 """ Asserts specified output does not contain the substring
17 specified by the argument text."""
18 assert output.find(text) < 0, "Output file contains unexpected text '%s'" % text
19
20
21 def assert_has_line(output, line, n=None):
22 """ Asserts the specified output contains the line specified by the
23 argument line. The exact number of occurrences can be optionally
24 specified by the argument n."""
25 if n is None:
26 match = re.search("^%s$" % re.escape(line), output, flags=re.MULTILINE)
27 assert match is not None, f"No line of output file was '{line}' (output was '{output}') "
28 else:
29 matches = re.findall("^%s$" % re.escape(line), output, flags=re.MULTILINE)
30 assert len(matches) == int(n), "Expected {} lines matching '{}' in output file (output was '{}'); found {}".format(n, line, output, len(matches))
31
32
33 def assert_has_n_lines(output, n):
34 """Asserts the specified output contains ``n`` lines."""
35 n_lines_found = len(output.splitlines())
36 assert n_lines_found == int(n), f"Expected {n} lines in output, found {n_lines_found} lines"
37
38
39 def assert_has_text_matching(output, expression):
40 """ Asserts the specified output contains text matching the
41 regular expression specified by the argument expression."""
42 match = re.search(expression, output)
43 assert match is not None, "No text matching expression '%s' was found in output file." % expression
44
45
46 def assert_has_line_matching(output, expression):
47 """ Asserts the specified output contains a line matching the
48 regular expression specified by the argument expression."""
49 match = re.search("^%s$" % expression, output, flags=re.MULTILINE)
50 assert match is not None, "No line matching expression '%s' was found in output file." % expression