summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Drung <bdrung@ubuntu.com>2011-07-09 12:01:34 +0200
committerBenjamin Drung <bdrung@ubuntu.com>2011-07-09 12:01:34 +0200
commitdf58f3a3d891a494232d6e49a5a1862a557e8930 (patch)
treef3b2f5e9c1dce38d1fcc476030559b95657ea65d /tests
parent352439516b288bb80a0c712e991cc440980f7e7c (diff)
Convert tabs to spaces in Python scripts and make pylint happier.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test-moz-version122
1 files changed, 65 insertions, 57 deletions
diff --git a/tests/test-moz-version b/tests/test-moz-version
index 7707b71..db6c282 100755
--- a/tests/test-moz-version
+++ b/tests/test-moz-version
@@ -25,73 +25,81 @@ import os
import sys
sys.path.insert(1, os.path.abspath(os.path.dirname(sys.argv[0]) + "/../src"))
-from moz_version import *
+from moz_version import compare_versions
# error codes
COMMAND_LINE_SYNTAX_ERROR = 1
TEST_FAILED_ERROR = 2
-test_pattern = (("1.-1", "lt", "1", True),
- ("1", "eq", "1.", True),
- ("1", "eq", "1.0", True),
- ("1", "eq", "1.0.0", True),
- ("1.0.0", "lt", "1.1a", True),
- ("1.1a", "lt", "1.1aa", True),
- ("1.1aa", "lt", "1.1ab", True),
- ("1.1ab", "lt", "1.1b", True),
- ("1.1b", "lt", "1.1c", True),
- ("1.1pre", "eq", "1.1pre0", True),
- ("1.1pre0", "eq", "1.0+", True),
- ("1.0+", "lt", "1.1pre1a", True),
- ("1.1pre1a", "lt", "1.1pre1aa", True),
- ("1.1pre1aa", "lt", "1.1pre1b", True),
- ("1.1pre1b", "lt", "1.1pre1", True),
- ("1.1pre1", "lt", "1.1pre2", True),
- ("1.1pre2", "lt", "1.1pre10", True),
- ("1.1pre10", "lt", "1.1.-1", True),
- ("1.1.-1", "lt", "1.1", True),
- ("1.1", "eq", "1.1.0", True),
- ("1.1.0", "eq", "1.1.00", True),
- ("1.1.00", "lt", "1.10", True),
- ("1.10", "lt", "1.*", True),
- ("1.*", "lt", "1.*.1", True),
- ("1.*.1", "lt", "2.0", True),
- ("1.*.1", "gt", "2.0", False),
- )
+TEST_PATTERN = (
+ ("1.-1", "lt", "1", True),
+ ("1", "eq", "1.", True),
+ ("1", "eq", "1.0", True),
+ ("1", "eq", "1.0.0", True),
+ ("1.0.0", "lt", "1.1a", True),
+ ("1.1a", "lt", "1.1aa", True),
+ ("1.1aa", "lt", "1.1ab", True),
+ ("1.1ab", "lt", "1.1b", True),
+ ("1.1b", "lt", "1.1c", True),
+ ("1.1pre", "eq", "1.1pre0", True),
+ ("1.1pre0", "eq", "1.0+", True),
+ ("1.0+", "lt", "1.1pre1a", True),
+ ("1.1pre1a", "lt", "1.1pre1aa", True),
+ ("1.1pre1aa", "lt", "1.1pre1b", True),
+ ("1.1pre1b", "lt", "1.1pre1", True),
+ ("1.1pre1", "lt", "1.1pre2", True),
+ ("1.1pre2", "lt", "1.1pre10", True),
+ ("1.1pre10", "lt", "1.1.-1", True),
+ ("1.1.-1", "lt", "1.1", True),
+ ("1.1", "eq", "1.1.0", True),
+ ("1.1.0", "eq", "1.1.00", True),
+ ("1.1.00", "lt", "1.10", True),
+ ("1.10", "lt", "1.*", True),
+ ("1.*", "lt", "1.*.1", True),
+ ("1.*.1", "lt", "2.0", True),
+ ("1.*.1", "gt", "2.0", False),
+)
def fail(message):
- print >> sys.stderr, "E: " + message
- sys.exit(TEST_FAILED_ERROR)
+ print >> sys.stderr, "E: " + message
+ sys.exit(TEST_FAILED_ERROR)
def test_compare(verbose=False):
- for pattern in test_pattern:
- if pattern[1] == "lt":
- if (compare_versions(pattern[0], pattern[2], verbose) < 0) != pattern[3]:
- fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
- elif pattern[1] == "eq":
- if (compare_versions(pattern[0], pattern[2], verbose) == 0) != pattern[3]:
- fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
- elif pattern[1] == "gt":
- if (compare_versions(pattern[0], pattern[2], verbose) > 0) != pattern[3]:
- fail('Test pattern "%s %s %s" failed (result should be %s).' % pattern)
- else:
- fail('Unknown pattern %s.' % (pattern[1]))
+ for pattern in TEST_PATTERN:
+ compare_result = compare_versions(pattern[0], pattern[2], verbose)
+ if pattern[1] == "lt":
+ if (compare_result < 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % \
+ pattern)
+ elif pattern[1] == "eq":
+ if (compare_result == 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % \
+ pattern)
+ elif pattern[1] == "gt":
+ if (compare_result > 0) != pattern[3]:
+ fail('Test pattern "%s %s %s" failed (result should be %s).' % \
+ pattern)
+ else:
+ fail('Unknown pattern %s.' % (pattern[1]))
-if __name__ == "__main__":
- try:
- long_opts = ["verbose"]
- opts, args = getopt.gnu_getopt(sys.argv[1:], "v", long_opts)
- except getopt.GetoptError, e:
- # print help information and exit:
- print >> sys.stderr, str(e) # will print something like "option -a not recognized"
- sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+def main():
+ try:
+ long_opts = ["verbose"]
+ opts = getopt.gnu_getopt(sys.argv[1:], "v", long_opts)[0]
+ except getopt.GetoptError, e:
+ # print help information and exit:
+ print >> sys.stderr, str(e)
+ sys.exit(COMMAND_LINE_SYNTAX_ERROR)
+
+ verbose = False
- verbose = False
+ for o, _ in opts:
+ if o in ("-v", "--verbose"):
+ verbose = True
+ else:
+ assert False, "unhandled option"
- for o, a in opts:
- if o in ("-v", "--verbose"):
- verbose = True
- else:
- assert False, "unhandled option"
+ test_compare(verbose)
- test_compare(verbose)
+if __name__ == "__main__":
+ main()