Skip to content

Commit

Permalink
Even in Python 2 ZConfig reads the config as text when starting up Zope.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Oct 3, 2018
1 parent 7d23b43 commit dc4976c
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/Zope2/Startup/tests/test_schema.py
Expand Up @@ -12,12 +12,12 @@
#
##############################################################################

import codecs
import os
import io
import tempfile
import unittest

import six
import ZConfig

from Zope2.Startup.options import ZopeWSGIOptions
Expand All @@ -43,10 +43,7 @@ def load_config_text(self, text):
# of the directory is checked. This handles this in a
# platform-independent way.
text = text.replace("<<INSTANCE_HOME>>", TEMPNAME)
if six.PY2:
sio = io.BytesIO(text)
else:
sio = io.StringIO(text)
sio = io.StringIO(text)

os.mkdir(TEMPNAME)
os.mkdir(TEMPVAR)
Expand All @@ -62,13 +59,12 @@ def test_load_config_template(self):
import Zope2.utilities
base = os.path.dirname(Zope2.utilities.__file__)
fn = os.path.join(base, "skel", "etc", "wsgi.conf.in")
f = open(fn)
text = f.read()
f.close()
with codecs.open(fn, encoding='utf-8') as f:
text = f.read()
self.load_config_text(text)

def test_environment(self):
conf, handler = self.load_config_text("""\
conf, handler = self.load_config_text(u"""\
# instancehome is here since it's required
instancehome <<INSTANCE_HOME>>
<environment>
Expand All @@ -82,7 +78,7 @@ def test_environment(self):
items, [("FEARFACTORY", "rocks"), ("NSYNC", "doesnt")])

def test_zodb_db(self):
conf, handler = self.load_config_text("""\
conf, handler = self.load_config_text(u"""\
instancehome <<INSTANCE_HOME>>
<zodb_db main>
<filestorage>
Expand All @@ -96,25 +92,25 @@ def test_zodb_db(self):
self.assertEqual(conf.databases[0].config.cache_size, 5000)

def test_max_conflict_retries_default(self):
conf, handler = self.load_config_text("""\
conf, handler = self.load_config_text(u"""\
instancehome <<INSTANCE_HOME>>
""")
self.assertEqual(conf.max_conflict_retries, 3)

def test_max_conflict_retries_explicit(self):
conf, handler = self.load_config_text("""\
conf, handler = self.load_config_text(u"""\
instancehome <<INSTANCE_HOME>>
max-conflict-retries 15
""")
self.assertEqual(conf.max_conflict_retries, 15)

def test_default_zpublisher_encoding(self):
conf, dummy = self.load_config_text("""\
conf, dummy = self.load_config_text(u"""\
instancehome <<INSTANCE_HOME>>
""")
self.assertEqual(conf.default_zpublisher_encoding, 'utf-8')

conf, dummy = self.load_config_text("""\
conf, dummy = self.load_config_text(u"""\
instancehome <<INSTANCE_HOME>>
default-zpublisher-encoding iso-8859-15
""")
Expand Down

0 comments on commit dc4976c

Please sign in to comment.