1 # Copyright (C) 2010, Thomas Leonard
2 # Visit http://0install.net for details.
4 from zeroinstall
import SafeException
5 from zeroinstall
.injector
import model
10 self
.test_iface
= None # The URI of the program being tested
12 self
.test_ifaces
= [] # [Interface] - list of interfaces with specified versions
13 self
.test_matrix
= {} # {URI: [version]} - versions of each interface to test
14 # (test_ifaces is needed because we care about the order)
17 self
.test_wrapper
= None # Command to execute to perform tests
18 self
.test_args
= [] # Arguments to pass to test script
20 # Yield a sequence of set((uri, version)), one for each combination to test
21 def get_combos(self
, ifaces
):
25 for version
in self
.test_matrix
[ifaces
[0]]:
26 for combo
in self
.get_combos(ifaces
[1:]):
27 combo
[ifaces
[0]] = version
30 def parse_arguments(options
, args
):
35 spec
.test_args
= args
[i
+ 1:]
38 if options
.test_command
:
39 spec
.test_wrapper
= options
.test_command
+ ' #'
41 raise SafeException("Can't specify arguments with --test-command")
47 if options
.command
== '':
50 spec
.command
= options
.command
53 logging
.info("Test command is '{command}'".format(command
= spec
.command
))
55 logging
.info("Test command is None")
59 if (x
[0].isdigit() or x
[0] in ',%.!') and iface
and '/' not in x
:
60 spec
.test_matrix
[iface
].append(x
)
62 assert x
not in spec
.test_matrix
, "Interface %s given twice!" % x
63 iface
= model
.canonical_iface_uri(x
)
64 spec
.test_matrix
[iface
] = []
65 spec
.test_ifaces
.append(iface
)
67 # We don't need to specify the version of the interface under test.
68 spec
.test_iface
= spec
.test_ifaces
[0]
69 if not spec
.test_matrix
[spec
.test_iface
]:
70 del spec
.test_matrix
[spec
.test_iface
]
71 del spec
.test_ifaces
[0]
73 # We do need a version for all the others (else what was the point of listing them?)
74 for iface
in spec
.test_ifaces
:
75 if not spec
.test_matrix
[iface
]:
76 raise SafeException("No versions given for interface %s" % iface
)