Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
py3 tests are green
Browse files Browse the repository at this point in the history
  • Loading branch information
goschtl committed Jan 19, 2018
1 parent b0ad93a commit 89c3a5d
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 80 deletions.
26 changes: 19 additions & 7 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --find-links to point to local resources, you can keep
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''

Expand All @@ -59,6 +59,8 @@
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--setuptools-version",
help="use a specific setuptools version")


options, args = parser.parse_args()
Expand All @@ -79,16 +81,20 @@

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)

if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version

ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources
Expand Down Expand Up @@ -128,10 +134,15 @@
_final_parts = '*final-', '*final'

def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
try:
return not parsed_version.is_prerelease
except AttributeError:
# Older setuptools
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True

index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
if find_links:
Expand Down Expand Up @@ -176,3 +187,4 @@ def _final_version(parsed_version):

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)

21 changes: 17 additions & 4 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
[buildout]
develop = .
parts = interpreter test
extends = https://raw.github.com/zopefoundation/groktoolkit/master/grok.cfg
parts = interpreter test omelette
extends =
https://raw.githubusercontent.com/zopefoundation/groktoolkit/resurrection-python3/grok.cfg
versions = versions

extensions =
mr.developer

auto-checkout =

[versions]
grokui.admin =
grokui.admin =

[sources]
grokui.base = git ${buildout:github}/grokui.base pushurl=${buildout:github_push}/grokui.base

[interpreter]
recipe = zc.recipe.egg
eggs = grokcore.layout
eggs = grokui.admin
interpreter = python

[test]
recipe = zc.recipe.testrunner
eggs = grokui.admin [test]
defaults = ['--tests-pattern', '^f?tests$', '-v', '-c', '--package=grokui.admin']

[omelette]
recipe = collective.recipe.omelette
eggs = ${test:eggs}
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from setuptools import setup, find_packages

tests_require = [
'zope.app.wsgi',
'zope.app.wsgi[test]',
'zope.principalregistry',
'zope.security',
'zope.securitypolicy',
'zope.testbrowser',
'zope.testing',
'zc.buildout',
]
Expand Down
2 changes: 1 addition & 1 deletion src/grokui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError, e:
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion src/grokui/admin/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InstallableApplication(object):
def __init__(self, klass):
self.__name__ = klass.__name__
self.classname = ".".join((klass.__module__, klass.__name__))
self.description = unicode(getattr(klass, '__doc__', u'') or u'')
self.description = getattr(klass, '__doc__', '') or ''


class ApplicationInfo(grok.View):
Expand Down
12 changes: 6 additions & 6 deletions src/grokui/admin/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import grok
import cgi
import time
import urllib2
import urlparse
import urllib.request

from persistent import Persistent
from grokui.admin.interfaces import ISecurityNotifier
from grokui.admin.utilities import getVersion, TimeoutableHTTPHandler
from grokui.base import Messages, IGrokUIRealm
import urllib.parse as urlparse

MSG_DISABLED = u'Security notifications are disabled.'

Expand Down Expand Up @@ -109,13 +109,13 @@ def fetchMessage(self):
url = urlparse.urljoin(self.lookup_url, filename)
# We create a HTTP handler with a timeout.
http_handler = TimeoutableHTTPHandler(timeout=self.lookup_timeout)
opener = urllib2.build_opener(http_handler)
req = urllib2.Request(url)
opener = urllib.request.build_opener(http_handler)
req = urllib.request.Request(url)
try:
message = opener.open(req).read()
self._message = cgi.escape(message)
self._message = cgi.escape(message.decode())
self._warningstate = True
except urllib2.HTTPError, e:
except urllib.request.HTTPError as e:
if e.code == 404:
# No security warning found, good message.
self._message = u''
Expand Down
8 changes: 4 additions & 4 deletions src/grokui/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _getInfo(self, ri):

def _getUptime(self, ri):
# make a unix "uptime" uptime format
uptime = long(ri.getUptime())
uptime = int(ri.getUptime())
minutes, seconds = divmod(uptime, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
Expand Down Expand Up @@ -212,7 +212,7 @@ def _getSize(self, db):
"""Get the database size in a human readable format.
"""
size = db.getSize()
if not isinstance(size, (int, long, float)):
if not isinstance(size, (int, float)):
return str(size)
return byteDisplay(size)

Expand All @@ -223,11 +223,11 @@ def pack(self, dbName, days):
self.flash('Error: Invalid Number')
return
db = getUtility(IDatabase, name=dbName)
print "DB: ", db, days
print("DB: ", db, days)
db.pack(days=days)
return
try:
db.pack(days=days)
self.flash('ZODB `%s` successfully packed.' % (dbName))
except FileStorageError, err:
except FileStorageError as err:
self.flash('ERROR packing ZODB `%s`: %s' % (dbName, err))
23 changes: 12 additions & 11 deletions src/grokui/admin/tests/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
Applications management
=======================
>>> from zope.app.wsgi.testlayer import Browser
>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.handleErrors = True
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
We fetch the standard page, which should provide us a menu to get all
installable grok applications/components.
>>> browser.open("http://localhost/")
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... <legend>Add application</legend>
Expand All @@ -19,7 +20,7 @@
The opening screen should inform us, that there are no applications
installed yet:
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... Currently no working...applications are installed.
Expand All @@ -31,7 +32,7 @@
>>> subform.getControl(name='name').value = 'my-mammoth-manager'
>>> subform.getControl('Create').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
...<legend>Installed applications</legend>
Expand All @@ -42,10 +43,10 @@
Launch the added mammoth manager
>>> mylink = browser.getLink('my-mammoth-manager').click()
>>> print browser.contents
>>> print(browser.contents)
Let's manage some mammoths!
>>> print browser.url
>>> print(browser.url)
http://localhost/my-mammoth-manager
We can also rename applications. For this we choose the application we
Expand All @@ -58,7 +59,7 @@
We get a form were we can enter new names::
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...<legend> Rename applications: </legend>...
Expand All @@ -69,7 +70,7 @@
Our app was indeed renamed::
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...<legend>Installed applications</legend>
...<a href="http://localhost/my-new-mammoth-manager">
Expand All @@ -83,23 +84,23 @@
>>> subform.getControl(name='name').value = 'my-new-mammoth-manager'
>>> subform.getControl('Create').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...Name `my-new-mammoth-manager` already in use.
...Please choose another name...
We are able to delete installed mammoth-managers
>>> browser.open("http://localhost/++grokui++/applications")
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... <legend>Installed applications</legend>
...
>>> ctrl = browser.getControl(name='items')
>>> ctrl.getControl(value='my-new-mammoth-manager').selected = True
>>> browser.getControl('Delete Selected').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... Currently no working applications are installed.
Expand Down
6 changes: 3 additions & 3 deletions src/grokui/admin/tests/brokenapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
We first setup the environment:
>>> from zope.app.wsgi.testlayer import Browser
>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Expand All @@ -28,7 +28,7 @@
>>> subform.getControl('Create').click()
Traceback (most recent call last):
...
DuplicationError: Intentional DuplicationError
zope.exceptions.interfaces.DuplicationError: Intentional DuplicationError
If, however, we try to add two working apps under same name, the UI
will inform us of the problem (without a traceback):
Expand All @@ -44,7 +44,7 @@
>>> subform.getControl(name='name').value = 'somename'
>>> subform.getControl('Create').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
...Name `somename` already in use. Please choose another name...
Expand Down
6 changes: 3 additions & 3 deletions src/grokui/admin/tests/brokenobjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
We first setup the environment:
>>> from zope.app.wsgi.testlayer import Browser
>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Expand Down Expand Up @@ -38,7 +38,7 @@
and the broken object should show up in the applications list:
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
...Currently no working applications are...installed...
Expand All @@ -54,7 +54,7 @@
>>> ctrl = browser.getControl(name='items')
>>> ctrl.getControl(value='mybrokenobj').selected = True
>>> browser.getControl('Delete Selected').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
...Application `mybrokenobj` was successfully deleted.
Expand Down
6 changes: 3 additions & 3 deletions src/grokui/admin/tests/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
When we create a new app, a grok.IObjectCreatedEvent is called:
>>> from zope.app.wsgi.testlayer import Browser
>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Expand Down Expand Up @@ -38,9 +38,9 @@ class App(grok.Application, grok.Container):

@grok.subscribe(App, grok.IObjectCreatedEvent)
def handle_my_event(obj, event):
print "ObjectCreated event happened."
print("ObjectCreated event happened.")


@grok.subscribe(App, grok.ApplicationAddedEvent)
def handle_app_initialized_event(obj, event):
print "ApplicationAdded event happened."
print("ApplicationAdded event happened.")
Loading

0 comments on commit 89c3a5d

Please sign in to comment.