summaryrefslogtreecommitdiffstats
path: root/doc/examples/versiontest.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/versiontest.py')
-rwxr-xr-xdoc/examples/versiontest.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/doc/examples/versiontest.py b/doc/examples/versiontest.py
new file mode 100755
index 0000000..fcc4c25
--- /dev/null
+++ b/doc/examples/versiontest.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python3
+
+# This is a simple clone of tests/versiontest.cc
+import re
+import sys
+
+import apt_pkg
+
+apt_pkg.init_config()
+apt_pkg.init_system()
+
+TestFile = apt_pkg.parse_commandline(apt_pkg.config, [], sys.argv)
+if len(TestFile) != 1:
+ print("Must have exactly 1 file name")
+ sys.exit(0)
+
+# Go over the file..
+list = open(TestFile[0])
+CurLine = 0
+while True:
+ Line = list.readline()
+ CurLine = CurLine + 1
+ if Line == "":
+ break
+ Line = Line.strip()
+ if len(Line) == 0 or Line[0] == "#":
+ continue
+
+ Split = re.split("[ \n]", Line)
+
+ # Check forward
+ if apt_pkg.version_compare(Split[0], Split[1]) != int(Split[2]):
+ print(
+ "Comparision failed on line %u. '%s' ? '%s' %i != %i"
+ % (
+ CurLine,
+ Split[0],
+ Split[1],
+ apt_pkg.version_compare(Split[0], Split[1]),
+ int(Split[2]),
+ )
+ )
+ # Check reverse
+ if apt_pkg.version_compare(Split[1], Split[0]) != -1 * int(Split[2]):
+ print(
+ "Comparision failed on line %u. '%s' ? '%s' %i != %i"
+ % (
+ CurLine,
+ Split[1],
+ Split[0],
+ apt_pkg.version_compare(Split[1], Split[0]),
+ -1 * int(Split[2]),
+ )
+ )