Commit 890a2376 authored by Stefan H. Holek's avatar Stefan H. Holek

Merged trunk r94458 and r94532 into 2.11 branch.

Replace messy tests with cleaned-up versions from trunk. The old tests deleted 'Zope2/version.txt' - WTFBBQ?
parent 58cd4451
...@@ -15,41 +15,51 @@ ...@@ -15,41 +15,51 @@
$Id$ $Id$
""" """
import os
import unittest import unittest
import Zope2
import App.version_txt
class VersionTextTestCase(unittest.TestCase): class VersionTextTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.fn = os.path.join(os.path.dirname(Zope2.__file__), "version.txt") self._resetModuleGlobals()
App.version_txt._test_reset()
def tearDown(self): def tearDown(self):
try: import os
os.unlink(self.fn) from App.version_txt import _version_file
except OSError: if _version_file is not None:
pass os.unlink(_version_file)
self._resetModuleGlobals()
def _resetModuleGlobals(self):
from App import version_txt
version_txt._filename = 'version.txt'
version_txt._version_file = None
version_txt._version_string = None
version_txt._zope_version = None
def writeVersion(self, s): def writeVersion(self, s):
f = open(self.fn, 'w') import os
f.write(s) import tempfile
f.close() from App import version_txt
assert version_txt._version_file is None
f, version_txt._version_file = tempfile.mkstemp()
os.write(f, s)
os.close(f)
def test_without_version_txt(self): def test_without_version_txt(self):
self.assertEqual(App.version_txt.getZopeVersion(), from App import version_txt
(-1, -1, -1, '', -1)) from App.version_txt import getZopeVersion
version_txt._filename = ''
self.assertEqual(getZopeVersion(), (-1, -1, -1, '', -1))
def test_with_version_txt_final(self): def test_with_version_txt_final(self):
from App.version_txt import getZopeVersion
self.writeVersion("Zope 2.6.1 (source release, python 2.1, linux2)") self.writeVersion("Zope 2.6.1 (source release, python 2.1, linux2)")
self.assertEqual(App.version_txt.getZopeVersion(), self.assertEqual(getZopeVersion(), (2, 6, 1, '', -1))
(2, 6, 1, '', -1))
def test_with_version_txt_beta(self): def test_with_version_txt_beta(self):
from App.version_txt import getZopeVersion
self.writeVersion("Zope 2.6.1b2 (source release, python 2.1, linux2)") self.writeVersion("Zope 2.6.1b2 (source release, python 2.1, linux2)")
self.assertEqual(App.version_txt.getZopeVersion(), self.assertEqual(getZopeVersion(), (2, 6, 1, 'b', 2))
(2, 6, 1, 'b', 2))
def test_suite(): def test_suite():
......
...@@ -14,24 +14,29 @@ ...@@ -14,24 +14,29 @@
$id$ $id$
""" """
import os, sys, re import os
import re
import sys
import Zope2 import Zope2
_location = os.path.dirname(Zope2.__file__)
_filename = 'version.txt'
_version_file = None
_version_string = None _version_string = None
_zope_version = None _zope_version = None
def _test_reset(): def _get_filename():
# Needed for testing. if _version_file is not None:
global _version_string, _zope_version return _version_file
_version_string = None return os.path.join(_location, _filename)
_zope_version = None
def _prep_version_data(): def _prep_version_data():
global _version_string, _zope_version global _version_string, _zope_version
if _version_string is None: if _version_string is None:
v = sys.version_info v = sys.version_info
pyver = "python %d.%d.%d, %s" % (v[0], v[1], v[2], sys.platform) pyver = "python %d.%d.%d, %s" % (v[0], v[1], v[2], sys.platform)
fn = os.path.join(os.path.dirname(Zope2.__file__), 'version.txt') fn = _get_filename()
expr = re.compile( expr = re.compile(
r'(?P<product>[A-Za-z0-9]+) +(?P<major>[0-9]+)' r'(?P<product>[A-Za-z0-9]+) +(?P<major>[0-9]+)'
'\.(?P<minor>[0-9]+)\.(?P<micro>[0-9]+)' '\.(?P<minor>[0-9]+)\.(?P<micro>[0-9]+)'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment