Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
15563c3f
Commit
15563c3f
authored
Apr 27, 2001
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial checkin
parent
c3a67c7e
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
928 additions
and
0 deletions
+928
-0
lib/python/ZTUtils/Batch.py
lib/python/ZTUtils/Batch.py
+171
-0
lib/python/ZTUtils/Iterator.py
lib/python/ZTUtils/Iterator.py
+137
-0
lib/python/ZTUtils/Tree.py
lib/python/ZTUtils/Tree.py
+288
-0
lib/python/ZTUtils/__init__.py
lib/python/ZTUtils/__init__.py
+95
-0
lib/python/ZTUtils/tests/framework.py
lib/python/ZTUtils/tests/framework.py
+150
-0
lib/python/ZTUtils/tests/run.py
lib/python/ZTUtils/tests/run.py
+16
-0
lib/python/ZTUtils/tests/testBatch.py
lib/python/ZTUtils/tests/testBatch.py
+45
-0
lib/python/ZTUtils/tests/testIterator.py
lib/python/ZTUtils/tests/testIterator.py
+26
-0
No files found.
lib/python/ZTUtils/Batch.py
0 → 100644
View file @
15563c3f
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
__doc__
=
'''Batch class, for iterating over a sequence in batches
$Id: Batch.py,v 1.1 2001/04/27 16:38:52 evan Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
from
ExtensionClass
import
Base
class
LazyPrevBatch
(
Base
):
def
__of__
(
self
,
parent
):
return
Batch
(
parent
.
_sequence
,
parent
.
_size
,
0
,
parent
.
_first
+
parent
.
overlap
,
parent
.
orphan
,
parent
.
overlap
)
class
LazyNextBatch
(
Base
):
def
__of__
(
self
,
parent
):
try
:
parent
.
_sequence
[
parent
.
end
]
except
IndexError
:
return
None
return
Batch
(
parent
.
_sequence
,
parent
.
_size
,
parent
.
end
-
parent
.
overlap
,
0
,
parent
.
orphan
,
parent
.
overlap
)
class
Batch
(
Base
):
"""Create a sequence batch"""
__allow_access_to_unprotected_subobjects__
=
1
previous
=
LazyPrevBatch
(
0
)
next
=
LazyNextBatch
(
1
)
def
__init__
(
self
,
sequence
,
size
,
start
=
0
,
end
=
0
,
orphan
=
3
,
overlap
=
0
):
start
=
start
+
1
start
,
end
,
sz
=
opt
(
start
,
end
,
size
,
orphan
,
sequence
)
self
.
_sequence
=
sequence
self
.
size
=
sz
self
.
_size
=
size
self
.
start
=
start
self
.
end
=
end
self
.
orphan
=
orphan
self
.
overlap
=
overlap
self
.
_first
=
max
(
start
-
1
,
0
)
self
.
length
=
self
.
end
-
self
.
_first
if
self
.
_first
==
0
:
self
.
previous
=
None
def
__getitem__
(
self
,
index
):
if
index
<
0
:
if
index
+
self
.
end
<
self
.
_first
:
raise
IndexError
,
index
return
self
.
_sequence
[
index
+
self
.
end
]
if
index
>=
self
.
end
:
raise
IndexError
,
index
return
self
.
_sequence
[
index
+
self
.
_first
]
def
__len__
(
self
):
return
self
.
length
def
opt
(
start
,
end
,
size
,
orphan
,
sequence
):
if
size
<
1
:
if
start
>
0
and
end
>
0
and
end
>=
start
:
size
=
end
+
1
-
start
else
:
size
=
7
if
start
>
0
:
try
:
sequence
[
start
-
1
]
except
:
start
=
len
(
sequence
)
if
end
>
0
:
if
end
<
start
:
end
=
start
else
:
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
elif
end
>
0
:
try
:
sequence
[
end
-
1
]
except
:
end
=
len
(
sequence
)
start
=
end
+
1
-
size
if
start
-
1
<
orphan
:
start
=
1
else
:
start
=
1
end
=
start
+
size
-
1
try
:
sequence
[
end
+
orphan
-
1
]
except
:
end
=
len
(
sequence
)
return
start
,
end
,
size
lib/python/ZTUtils/Iterator.py
0 → 100644
View file @
15563c3f
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
__doc__
=
'''Iterator class
$Id: Iterator.py,v 1.1 2001/04/27 16:38:52 evan Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
class
Iterator
:
'''Simple Iterator class'''
__allow_access_to_unprotected_subobjects__
=
1
def
__init__
(
self
,
seq
):
self
.
seq
=
seq
self
.
nextIndex
=
0
def
next
(
self
):
i
=
self
.
nextIndex
try
:
self
.
seq
[
i
]
except
IndexError
:
return
0
self
.
index
=
i
self
.
nextIndex
=
i
+
1
return
1
def
number
(
self
):
return
self
.
nextIndex
def
even
(
self
):
return
not
self
.
index
%
2
def
odd
(
self
):
return
self
.
index
%
2
def
letter
(
self
,
base
=
ord
(
'a'
),
radix
=
26
):
index
=
self
.
index
s
=
''
while
1
:
index
,
off
=
divmod
(
index
,
radix
)
s
=
chr
(
base
+
off
)
+
s
if
not
index
:
return
s
def
Letter
(
self
):
return
self
.
letter
(
base
=
ord
(
'A'
))
def
start
(
self
):
return
self
.
nextIndex
==
1
def
end
(
self
):
try
:
self
.
seq
[
self
.
nextIndex
]
except
IndexError
:
return
1
return
0
def
item
(
self
):
return
self
.
seq
[
self
.
index
]
def
length
(
self
):
return
len
(
self
.
seq
)
lib/python/ZTUtils/Tree.py
0 → 100644
View file @
15563c3f
This diff is collapsed.
Click to expand it.
lib/python/ZTUtils/__init__.py
0 → 100644
View file @
15563c3f
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
__doc__
=
'''Package of template utility classes and functions.
$Id: __init__.py,v 1.1 2001/04/27 16:38:52 evan Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
__allow_access_to_unprotected_subobjects__
=
1
__roles__
=
None
from
Batch
import
Batch
from
Iterator
import
Iterator
from
Tree
import
TreeMaker
,
encodeExpansion
,
decodeExpansion
,
a2b
,
b2a
lib/python/ZTUtils/tests/framework.py
0 → 100644
View file @
15563c3f
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
######################################################################
# Set up unit testing framework
#
# The following code should be at the top of every test module:
#
# import os, sys
# execfile(os.path.join(sys.path[0], 'framework.py'))
#
# ...and the following at the bottom:
#
# if __name__ == '__main__':
# main()
import
string
scriptdir
=
sys
.
path
[
0
]
input_dir
=
os
.
path
.
join
(
scriptdir
,
'input'
)
output_dir
=
os
.
path
.
join
(
scriptdir
,
'output'
)
if
not
sys
.
modules
.
has_key
(
'unittest'
):
if
os
.
path
.
abspath
(
scriptdir
)
==
os
.
path
.
abspath
(
'.'
):
# We're in the tests directory, and need to find unittest.
cwd
=
os
.
getcwd
()
while
1
:
for
ext
in
'py'
,
'pyc'
,
'pyo'
,
'pyd'
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
'unittest.'
+
ext
)):
break
else
:
cwd
,
lastdir
=
os
.
path
.
split
(
cwd
)
if
lastdir
:
continue
break
sys
.
path
.
insert
(
1
,
cwd
)
else
:
# We must be in the same directory as unittest
sys
.
path
.
insert
(
1
,
''
)
import
unittest
TestRunner
=
unittest
.
TextTestRunner
def
read_input
(
filename
):
filename
=
os
.
path
.
join
(
input_dir
,
filename
)
return
open
(
filename
,
'r'
).
read
()
def
read_output
(
filename
):
filename
=
os
.
path
.
join
(
output_dir
,
filename
)
return
open
(
filename
,
'r'
).
read
()
def
main
():
if
len
(
sys
.
argv
)
>
1
:
errs
=
globals
()[
sys
.
argv
[
1
]]()
else
:
errs
=
TestRunner
().
run
(
test_suite
())
sys
.
exit
(
errs
and
1
or
0
)
def
debug
():
test_suite
().
debug
()
def
pdebug
():
import
pdb
pdb
.
run
(
'debug()'
)
lib/python/ZTUtils/tests/run.py
0 → 100755
View file @
15563c3f
#! /usr/bin/env python1.5
"""Run all tests."""
import
os
,
sys
,
glob
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
def
test_suite
():
suite
=
unittest
.
TestSuite
()
for
mname
in
glob
.
glob
(
os
.
path
.
join
(
sys
.
path
[
0
],
'test*.py'
)):
mname
=
os
.
path
.
split
(
mname
)[
1
][:
-
3
]
m
=
__import__
(
mname
)
suite
.
addTest
(
m
.
test_suite
())
return
suite
if
__name__
==
"__main__"
:
main
()
lib/python/ZTUtils/tests/testBatch.py
0 → 100644
View file @
15563c3f
import
os
,
sys
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
import
string
from
ZTUtils
import
Batch
class
BatchTests
(
unittest
.
TestCase
):
def
testEmpty
(
self
):
'''Test empty Batch'''
b
=
Batch
([],
5
)
assert
b
.
previous
is
None
assert
b
.
next
is
None
assert
len
(
b
)
==
b
.
start
==
b
.
end
==
0
,
(
len
(
b
),
b
.
start
,
b
.
end
)
def
testSingle
(
self
):
'''Test single Batch'''
for
bsize
in
range
(
1
,
6
):
seq
=
range
(
bsize
)
b
=
Batch
(
seq
,
5
)
assert
b
.
previous
is
None
assert
b
.
next
is
None
assert
b
.
start
==
1
,
b
.
start
assert
len
(
b
)
==
b
.
end
==
bsize
for
i
in
seq
:
assert
b
[
i
]
==
i
,
(
b
[
i
],
i
)
neg
=
-
1
-
i
assert
b
[
neg
]
==
(
bsize
+
neg
),
(
b
[
neg
],
(
bsize
+
neg
))
def
testOrphan
(
self
):
'''Test orphan collection'''
for
bsize
in
(
6
,
7
):
b
=
Batch
(
range
(
bsize
),
5
)
assert
b
.
next
is
None
assert
len
(
b
)
==
bsize
b
=
Batch
(
range
(
8
),
5
)
assert
len
(
b
)
==
5
assert
len
(
b
.
next
)
==
3
def
test_suite
():
return
unittest
.
makeSuite
(
BatchTests
)
if
__name__
==
'__main__'
:
main
()
lib/python/ZTUtils/tests/testIterator.py
0 → 100644
View file @
15563c3f
import
os
,
sys
execfile
(
os
.
path
.
join
(
sys
.
path
[
0
],
'framework.py'
))
from
ZTUtils
import
Iterator
class
IteratorTests
(
unittest
.
TestCase
):
def
testIterator0
(
self
):
it
=
Iterator
(())
assert
not
it
.
next
(),
"Empty iterator"
def
testIterator1
(
self
):
it
=
Iterator
((
1
,))
assert
it
.
next
()
and
not
it
.
next
(),
"Single-element iterator"
def
testIterator2
(
self
):
it
=
Iterator
(
'text'
)
for
c
in
'text'
:
assert
it
.
next
(),
"Multi-element iterator"
assert
not
it
.
next
(),
"Multi-element iterator"
def
test_suite
():
return
unittest
.
makeSuite
(
IteratorTests
)
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment