Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored tests for easier readability.
- Loading branch information
0 parents
commit 82f02b6
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE | ||
# | ||
############################################################################## | ||
"""ZODB undo support for Zope2. | ||
This package is used to support the Prefix object that Zope uses for | ||
undo. It is a separate package only to aid configuration management. | ||
This package is included in Zope and ZODB3, so that ZODB3 is suitable | ||
for running a ZEO server that handles Zope undo. | ||
""" | ||
|
||
class Prefix: | ||
"""A Prefix() is equal to any path it is a prefix of. | ||
This class can be compared to a string. | ||
The comparison will return True if all path elements of the | ||
Prefix are found at the beginning of the string being compared. | ||
Two Prefixes can not be compared. | ||
""" | ||
|
||
__no_side_effects__ = 1 | ||
|
||
def __init__(self, path): | ||
path_list = path.split('/') | ||
self.length = len(path_list) | ||
self.path = path_list | ||
|
||
def __cmp__(self, o): | ||
other_path = o.split('/') | ||
return cmp(other_path[:self.length], self.path) | ||
|
||
def __repr__(self): | ||
# makes failing tests easier to read | ||
return "Prefix('%s')" % '/'.join(self.path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE | ||
# | ||
############################################################################## | ||
from ZopeUndo.Prefix import Prefix | ||
|
||
import unittest | ||
|
||
class PrefixTest(unittest.TestCase): | ||
|
||
def test(self): | ||
p1 = Prefix("/a/b") | ||
for equal in ("/a/b", "/a/b/c", "/a/b/c/d"): | ||
self.assertEqual(p1, equal) | ||
for notEqual in ("", "/a/c", "/a/bbb", "///"): | ||
self.assertNotEqual(p1, notEqual) | ||
|
||
p2 = Prefix("") | ||
for equal in ("", "/", "/def", "/a/b", "/a/b/c", "/a/b/c/d"): | ||
self.assertEqual(p2, equal) | ||
|
||
def test_suite(): | ||
return unittest.makeSuite(PrefixTest) |