commit/galaxy-central: jmchilton: PEP-8 fixes for test.base.asserts.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/e4e1f70bc2d1/ Changeset: e4e1f70bc2d1 User: jmchilton Date: 2014-11-26 01:57:56+00:00 Summary: PEP-8 fixes for test.base.asserts. Some of the first Python code I ever wrote - and one can tell :). Affected #: 4 files diff -r bfa13d090966889c74512497bfcaafb732c08a41 -r e4e1f70bc2d1a84219038b7e58b933a94b424da7 test/base/asserts/__init__.py --- a/test/base/asserts/__init__.py +++ b/test/base/asserts/__init__.py @@ -8,7 +8,7 @@ # Code for loading modules containing assertion checking functions, to # create a new module of assertion functions, create the needed python # source file "test/base/asserts/<MODULE_NAME>.py" and add -# <MODULE_NAME> to the list of assertion module names defined above. +# <MODULE_NAME> to the list of assertion module names defined above. assertion_modules = [] for assertion_module_name in assertion_module_names: full_assertion_module_name = 'base.asserts.' + assertion_module_name @@ -19,7 +19,8 @@ assertion_module = sys.modules[full_assertion_module_name] assertion_modules.append(assertion_module) except Exception, e: - log.exception( 'Failed to load assertion module: %s %s' % (assertion_module_name, str(e))) + log.exception('Failed to load assertion module: %s %s' % (assertion_module_name, str(e))) + def verify_assertions(data, assertion_description_list): """ This function takes a list of assertions and a string to check @@ -27,6 +28,7 @@ for assertion_description in assertion_description_list: verify_assertion(data, assertion_description) + def verify_assertion(data, assertion_description): tag = assertion_description["tag"] assert_function_name = "assert_" + tag @@ -73,4 +75,3 @@ # TODO: Verify all needed function arguments are specified. assert_function(**args) - diff -r bfa13d090966889c74512497bfcaafb732c08a41 -r e4e1f70bc2d1a84219038b7e58b933a94b424da7 test/base/asserts/tabular.py --- a/test/base/asserts/tabular.py +++ b/test/base/asserts/tabular.py @@ -1,13 +1,15 @@ import re + def get_first_line(output): - match = re.search("^(.*)$", output, flags = re.MULTILINE) + match = re.search("^(.*)$", output, flags=re.MULTILINE) if match is None: return None else: return match.group(1) -def assert_has_n_columns(output, n, sep = '\t'): + +def assert_has_n_columns(output, n, sep='\t'): """ Asserts the tabular output contains n columns. The optional sep argument specifies the column seperator used to determine the number of columns.""" diff -r bfa13d090966889c74512497bfcaafb732c08a41 -r e4e1f70bc2d1a84219038b7e58b933a94b424da7 test/base/asserts/text.py --- a/test/base/asserts/text.py +++ b/test/base/asserts/text.py @@ -1,30 +1,34 @@ import re + def assert_has_text(output, text): """ Asserts specified output contains the substring specified by the argument text.""" assert output.find(text) >= 0, "Output file did not contain expected text '%s' (ouptut '%s')" % (text, output) - + + def assert_not_has_text(output, text): """ Asserts specified output does not contain the substring specified the argument text.""" assert output.find(text) < 0, "Output file contains unexpected text '%s'" % text + def assert_has_line(output, line): """ Asserts the specified output contains the line specified the argument line.""" - match = re.search("^%s$" % re.escape(line), output, flags = re.MULTILINE) - assert match != None, "No line of output file was '%s' (output was '%s') " % (line, output) + match = re.search("^%s$" % re.escape(line), output, flags=re.MULTILINE) + assert match is not None, "No line of output file was '%s' (output was '%s') " % (line, output) + def assert_has_text_matching(output, expression): """ Asserts the specified output contains text matching the regular expression specified by the argument expression.""" match = re.search(expression, output) - assert match != None, "No text matching expression '%s' was found in output file." % expression + assert match is not None, "No text matching expression '%s' was found in output file." % expression + def assert_has_line_matching(output, expression): """ Asserts the specified output contains a line matching the regular expression specified by the argument expression.""" - match = re.search("^%s$" % expression, output, flags = re.MULTILINE) - assert match != None, "No line matching expression '%s' was found in output file." % expression - + match = re.search("^%s$" % expression, output, flags=re.MULTILINE) + assert match is not None, "No line matching expression '%s' was found in output file." % expression diff -r bfa13d090966889c74512497bfcaafb732c08a41 -r e4e1f70bc2d1a84219038b7e58b933a94b424da7 test/base/asserts/xml.py --- a/test/base/asserts/xml.py +++ b/test/base/asserts/xml.py @@ -1,77 +1,88 @@ import elementtree.ElementTree import re + # Helper functions used to work with XML output. def to_xml(output): - return elementtree.ElementTree.fromstring(output) + return elementtree.ElementTree.fromstring(output) + def xml_find_text(output, path): - xml = to_xml(output) - text = xml.findtext(path) - return text + xml = to_xml(output) + text = xml.findtext(path) + return text + def xml_find(output, path): - xml = to_xml(output) - return xml.find(path) + xml = to_xml(output) + return xml.find(path) + def assert_is_valid_xml(output): - """ Simple assertion that just verifies the specified output - is valid XML.""" - try: - to_xml(output) - except Exception, e: - # TODO: Narrow caught exception to just parsing failure - raise AssertionError("Expected valid XML, but could not parse output. %s" % str(e)) + """ Simple assertion that just verifies the specified output + is valid XML.""" + try: + to_xml(output) + except Exception, e: + # TODO: Narrow caught exception to just parsing failure + raise AssertionError("Expected valid XML, but could not parse output. %s" % str(e)) + def assert_has_element_with_path(output, path): - """ Asserts the specified output has at least one XML element with a - path matching the specified path argument. Valid paths are the - simplified subsets of XPath implemented by elementtree (currently - Galaxy makes use of elementtree 1.2). See - http://effbot.org/zone/element-xpath.htm for more information.""" - if xml_find(output, path) is None: - errmsg = "Expected to find XML element matching expression %s, not such match was found." % path - raise AssertionError(errmsg) + """ Asserts the specified output has at least one XML element with a + path matching the specified path argument. Valid paths are the + simplified subsets of XPath implemented by elementtree (currently + Galaxy makes use of elementtree 1.2). See + http://effbot.org/zone/element-xpath.htm for more information.""" + if xml_find(output, path) is None: + errmsg = "Expected to find XML element matching expression %s, not such match was found." % path + raise AssertionError(errmsg) + def assert_has_n_elements_with_path(output, path, n): - """ Asserts the specified output has exactly n elements matching the - path specified.""" - xml = to_xml(output) - n = int(n) - num_elements = len(xml.findall(path)) - if num_elements != n: - errmsg = "Expected to find %d elements with path %s, but %d were found." % (n, path, num_elements) - raise AssertionError(errmsg) + """ Asserts the specified output has exactly n elements matching the + path specified.""" + xml = to_xml(output) + n = int(n) + num_elements = len(xml.findall(path)) + if num_elements != n: + errmsg = "Expected to find %d elements with path %s, but %d were found." % (n, path, num_elements) + raise AssertionError(errmsg) + def assert_element_text_matches(output, path, expression): - """ Asserts the text of the first element matching the specified - path matches the specified regular expression.""" - text = xml_find_text(output, path) - if re.match(expression, text) is None: - errmsg = "Expected element with path '%s' to contain text matching '%s', instead text '%s' was found." % (path, text, actual_text) - raise AssertionError(errmsg) + """ Asserts the text of the first element matching the specified + path matches the specified regular expression.""" + text = xml_find_text(output, path) + if re.match(expression, text) is None: + errmsg = "Expected element with path '%s' to contain text matching '%s', instead text '%s' was found." % (path, expression, text) + raise AssertionError(errmsg) + def assert_element_text_is(output, path, text): - """ Asserts the text of the first element matching the specified - path matches exactly the specified text. """ - assert_element_text_matches(output, path, re.escape(text)) + """ Asserts the text of the first element matching the specified + path matches exactly the specified text. """ + assert_element_text_matches(output, path, re.escape(text)) + def assert_attribute_matches(output, path, attribute, expression): - """ Asserts the specified attribute of the first element matching - the specified path matches the specified regular expression.""" - xml = xml_find(output, path) - attribute_value = xml.attrib[attribute] - if re.match(expression, attribute_value) is None: - errmsg = "Expected attribute '%s' on element with path '%s' to match '%s', instead attribute value was '%s'." % (attribute, path, expression, attribute_value) - raise AssertionError(errmsg) + """ Asserts the specified attribute of the first element matching + the specified path matches the specified regular expression.""" + xml = xml_find(output, path) + attribute_value = xml.attrib[attribute] + if re.match(expression, attribute_value) is None: + errmsg = "Expected attribute '%s' on element with path '%s' to match '%s', instead attribute value was '%s'." % (attribute, path, expression, attribute_value) + raise AssertionError(errmsg) + def assert_attribute_is(output, path, attribute, text): - """ Asserts the specified attribute of the first element matching - the specified path matches exactly the specified text.""" - assert_attribute_matches(output, path, attribute, re.escape(text)) + """ Asserts the specified attribute of the first element matching + the specified path matches exactly the specified text.""" + assert_attribute_matches(output, path, attribute, re.escape(text)) + def assert_element_text(output, path, verify_assertions_function, children): - """ Recursively checks the specified assertions against the text of - the first element matching the specified path.""" - text = xml_find_text(output, path) - verify_assertions_function(text, children) + """ Recursively checks the specified assertions against the text of + the first element matching the specified path.""" + text = xml_find_text(output, path) + verify_assertions_function(text, children) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org