2 # -*- coding: utf-8 -*-
6 Functional CLI testing using the PyPI RSS feed to try to create an ebuild
11 __docformat__ = 'restructuredtext'
19 Add switch for --pretend make default write ebuilds
20 Make option to write ebuild to tempdir and then cleanup after test is done
26 if sys.version_info[0] == 2 and sys.version_info[1] == 5:
27 #Python >=2.5 has elementtree
28 from xml.etree.cElementTree import iterparse
31 #Python <2.5 has elementtree as 3rd party module
32 from cElementTree import iterparse
34 print "You need to install cElementTree"
37 PYPI_URL = 'http://www.python.org/pypi?:action=rss'
39 #Packages we don't want to test. Mainly ones that require svn auth
40 SKIP = ['byCycleCore']
42 def get_pkg_ver(pv, add_quotes=True):
43 """Return package name and version"""
46 #Normal package_name 1.0
47 pkg_name, ver = pv.split()
52 pkg_name = "'%s'" % " ".join(parts[:-1])
54 pkg_name = "%s" % " ".join(parts[:-1])
57 def cli_test(pypi_xml):
58 """Test the command-line tool"""
59 for event, elem in iterparse(pypi_xml):
60 if elem.tag == "title":
61 if not elem.text.startswith('Cheese Shop recent updates'):
62 pkg_name, ver = get_pkg_ver(elem.text)
63 if pkg_name not in SKIP:
64 #If I don't use os.system for the echo's, all the msgs
65 #appear at the end of a log when redirecting output
66 os.system('echo Testing %s' % elem.text)
67 os.system('g-pypi -V %s' % pkg_name)
68 os.system('echo %s' % ('-' * 79))
71 if __name__ == "__main__":
72 cli_test(urllib.urlopen(PYPI_URL))