plugins_index.py and test run under py33
changed a message a bit since issue405 has actually been resolved
This commit is contained in:
parent
2058f11931
commit
ee5d2eb696
|
@ -5,6 +5,7 @@ pytest plugins taken directly from a live PyPI server.
|
||||||
This will evolve to include test compatibility (pythons and pytest versions)
|
This will evolve to include test compatibility (pythons and pytest versions)
|
||||||
information also.
|
information also.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import datetime
|
import datetime
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
@ -12,16 +13,29 @@ import itertools
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import xmlrpclib
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def get_proxy(url):
|
||||||
|
"""
|
||||||
|
wrapper function to obtain a xmlrpc proxy, taking in account import
|
||||||
|
differences between python 2.X and 3.X
|
||||||
|
|
||||||
|
:param url: url to bind the proxy to
|
||||||
|
:return: a ServerProxy instance
|
||||||
|
"""
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
from xmlrpclib import ServerProxy
|
||||||
|
else:
|
||||||
|
from xmlrpc.client import ServerProxy
|
||||||
|
return ServerProxy(url)
|
||||||
|
|
||||||
|
|
||||||
def iter_plugins(client, search='pytest-'):
|
def iter_plugins(client, search='pytest-'):
|
||||||
"""
|
"""
|
||||||
Returns an iterator of (name, version) from PyPI.
|
Returns an iterator of (name, version) from PyPI.
|
||||||
|
|
||||||
:param client: xmlrpclib.ServerProxy
|
:param client: ServerProxy
|
||||||
:param search: package names to search for
|
:param search: package names to search for
|
||||||
"""
|
"""
|
||||||
for plug_data in client.search({'name': search}):
|
for plug_data in client.search({'name': search}):
|
||||||
|
@ -50,17 +64,17 @@ def obtain_plugins_table(plugins, client):
|
||||||
should not be linked to anything.
|
should not be linked to anything.
|
||||||
|
|
||||||
:param plugins: list of (name, version)
|
:param plugins: list of (name, version)
|
||||||
:param client: xmlrpclib.ServerProxy
|
:param client: ServerProxy
|
||||||
"""
|
"""
|
||||||
rows = []
|
rows = []
|
||||||
ColumnData = namedtuple('ColumnData', 'text link')
|
ColumnData = namedtuple('ColumnData', 'text link')
|
||||||
headers = ['Name', 'Author', 'Downloads', 'Python 2.7', 'Python 3.3',
|
headers = ['Name', 'Author', 'Downloads', 'Python 2.7', 'Python 3.3',
|
||||||
'Summary']
|
'Summary']
|
||||||
pytest_version = pytest.__version__
|
pytest_version = pytest.__version__
|
||||||
print '*** pytest-{0} ***'.format(pytest_version)
|
print('*** pytest-{0} ***'.format(pytest_version))
|
||||||
plugins = list(plugins)
|
plugins = list(plugins)
|
||||||
for index, (package_name, version) in enumerate(plugins):
|
for index, (package_name, version) in enumerate(plugins):
|
||||||
print package_name, version, '...',
|
print(package_name, version, '...', end='')
|
||||||
|
|
||||||
release_data = client.release_data(package_name, version)
|
release_data = client.release_data(package_name, version)
|
||||||
download_count = release_data['downloads']['last_month']
|
download_count = release_data['downloads']['last_month']
|
||||||
|
@ -84,7 +98,7 @@ def obtain_plugins_table(plugins, client):
|
||||||
assert len(row) == len(headers)
|
assert len(row) == len(headers)
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
|
||||||
print 'OK (%d%%)' % ((index + 1) * 100 / len(plugins))
|
print('OK (%d%%)' % ((index + 1) * 100 / len(plugins)))
|
||||||
|
|
||||||
return headers, rows
|
return headers, rows
|
||||||
|
|
||||||
|
@ -118,32 +132,34 @@ def generate_plugins_index_from_table(filename, headers, rows):
|
||||||
def get_row_limiter(char):
|
def get_row_limiter(char):
|
||||||
return ' '.join(char * length for length in column_lengths)
|
return ' '.join(char * length for length in column_lengths)
|
||||||
|
|
||||||
with file(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
# write welcome
|
# write welcome
|
||||||
print >> f, '.. _plugins_index:'
|
print('.. _plugins_index:', file=f)
|
||||||
print >> f
|
print(file=f)
|
||||||
print >> f, 'List of Third-Party Plugins'
|
print('List of Third-Party Plugins', file=f)
|
||||||
print >> f, '==========================='
|
print('===========================', file=f)
|
||||||
print >> f
|
print(file=f)
|
||||||
|
|
||||||
# table
|
# table
|
||||||
print >> f, get_row_limiter('=')
|
print(get_row_limiter('='), file=f)
|
||||||
for i, header in enumerate(headers):
|
formatted_headers = [
|
||||||
print >> f, '{0:^{fill}}'.format(header, fill=column_lengths[i]),
|
'{0:^{fill}}'.format(header, fill=column_lengths[i])
|
||||||
print >> f
|
for i, header in enumerate(headers)]
|
||||||
print >> f, get_row_limiter('=')
|
print(*formatted_headers, file=f)
|
||||||
|
print(get_row_limiter('='), file=f)
|
||||||
|
|
||||||
for column_texts in table_texts:
|
for column_texts in table_texts:
|
||||||
for i, row_text in enumerate(column_texts):
|
formatted_rows = [
|
||||||
print >> f, '{0:^{fill}}'.format(row_text,
|
'{0:^{fill}}'.format(row_text, fill=column_lengths[i])
|
||||||
fill=column_lengths[i]),
|
for i, row_text in enumerate(column_texts)
|
||||||
print >> f
|
]
|
||||||
print >> f
|
print(*formatted_rows, file=f)
|
||||||
print >> f, get_row_limiter('=')
|
print(file=f)
|
||||||
print >> f
|
print(get_row_limiter('='), file=f)
|
||||||
print >> f, '*(Downloads are given from last month only)*'
|
print(file=f)
|
||||||
print >> f
|
print('*(Downloads are given from last month only)*', file=f)
|
||||||
print >> f, '*(Updated on %s)*' % _get_today_as_str()
|
print(file=f)
|
||||||
|
print('*(Updated on %s)*' % _get_today_as_str(), file=f)
|
||||||
|
|
||||||
|
|
||||||
def _get_today_as_str():
|
def _get_today_as_str():
|
||||||
|
@ -158,7 +174,7 @@ def generate_plugins_index(client, filename):
|
||||||
Generates an RST file with a table of the latest pytest plugins found in
|
Generates an RST file with a table of the latest pytest plugins found in
|
||||||
PyPI.
|
PyPI.
|
||||||
|
|
||||||
:param client: xmlrpclib.ServerProxy
|
:param client: ServerProxy
|
||||||
:param filename: output filename
|
:param filename: output filename
|
||||||
"""
|
"""
|
||||||
plugins = get_latest_versions(iter_plugins(client))
|
plugins = get_latest_versions(iter_plugins(client))
|
||||||
|
@ -182,12 +198,13 @@ def main(argv):
|
||||||
help='url of PyPI server to obtain data from [default: %default]')
|
help='url of PyPI server to obtain data from [default: %default]')
|
||||||
(options, _) = parser.parse_args(argv[1:])
|
(options, _) = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
client = xmlrpclib.ServerProxy(options.url)
|
client = get_proxy(options.url)
|
||||||
generate_plugins_index(client, options.filename)
|
generate_plugins_index(client, options.filename)
|
||||||
|
|
||||||
print
|
print()
|
||||||
print '%s Updated.' % options.filename
|
print('%s Updated.' % options.filename)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv))
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import os
|
import os
|
||||||
import xmlrpclib
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(
|
@pytest.mark.xfail(reason="not a core pytest test")
|
||||||
reason="issue405 fails, not py33 ready, not a core pytest test")
|
|
||||||
def test_plugins_index(tmpdir, monkeypatch):
|
def test_plugins_index(tmpdir, monkeypatch):
|
||||||
"""
|
"""
|
||||||
Blackbox testing for plugins_index script. Calls main() generating a file
|
Blackbox testing for plugins_index script. Calls main() generating a file
|
||||||
|
@ -58,7 +56,9 @@ def test_plugins_index(tmpdir, monkeypatch):
|
||||||
}
|
}
|
||||||
return results[(package_name, version)]
|
return results[(package_name, version)]
|
||||||
|
|
||||||
monkeypatch.setattr(xmlrpclib, 'ServerProxy', DummyProxy, 'foo')
|
|
||||||
|
monkeypatch.setattr(plugins_index, 'get_proxy', lambda url: DummyProxy(url),
|
||||||
|
'foo')
|
||||||
monkeypatch.setattr(plugins_index, '_get_today_as_str',
|
monkeypatch.setattr(plugins_index, '_get_today_as_str',
|
||||||
lambda: '2013-10-20')
|
lambda: '2013-10-20')
|
||||||
|
|
||||||
|
@ -66,13 +66,13 @@ def test_plugins_index(tmpdir, monkeypatch):
|
||||||
assert plugins_index.main(
|
assert plugins_index.main(
|
||||||
['', '-f', output_file, '-u', DummyProxy.expected_url]) == 0
|
['', '-f', output_file, '-u', DummyProxy.expected_url]) == 0
|
||||||
|
|
||||||
with file(output_file, 'rU') as f:
|
with open(output_file, 'rU') as f:
|
||||||
obtained_output = f.read()
|
obtained_output = f.read()
|
||||||
expected_output = get_expected_output()
|
expected_output = get_expected_output()
|
||||||
|
|
||||||
if obtained_output != expected_output:
|
if obtained_output != expected_output:
|
||||||
obtained_file = os.path.splitext(__file__)[0] + '.obtained.rst'
|
obtained_file = os.path.splitext(__file__)[0] + '.obtained.rst'
|
||||||
with file(obtained_file, 'w') as f:
|
with open(obtained_file, 'w') as f:
|
||||||
f.write(obtained_output)
|
f.write(obtained_output)
|
||||||
|
|
||||||
assert obtained_output == expected_output
|
assert obtained_output == expected_output
|
||||||
|
|
Loading…
Reference in New Issue