* seq/string utility'leri implement et:
- concat, listeleri birlestir - multisplit, string.split 'i extend et * version class'ini tamir et ve testi gecirt
This commit is contained in:
@@ -18,10 +18,21 @@ class UtilError(Exception):
|
|||||||
|
|
||||||
# string/list functions
|
# string/list functions
|
||||||
|
|
||||||
|
def concat(l):
|
||||||
|
"""concatenate a list of lists"""
|
||||||
|
return reduce( lambda x,y: x+y, l )
|
||||||
|
|
||||||
def strlist(l):
|
def strlist(l):
|
||||||
"""concatenate string reps of l's elements"""
|
"""concatenate string reps of l's elements"""
|
||||||
return string.join(map(lambda x: str(x) + ' ', l))
|
return string.join(map(lambda x: str(x) + ' ', l))
|
||||||
|
|
||||||
|
def multisplit(str, chars):
|
||||||
|
""" split str with any of chars"""
|
||||||
|
l = [str]
|
||||||
|
for c in chars:
|
||||||
|
l = concat(map(lambda x:x.split(c), l))
|
||||||
|
return l
|
||||||
|
|
||||||
def same(l):
|
def same(l):
|
||||||
"check if all elements of a sequence are equal"
|
"check if all elements of a sequence are equal"
|
||||||
if len(l)==0:
|
if len(l)==0:
|
||||||
|
|||||||
+3
-1
@@ -1,8 +1,10 @@
|
|||||||
# version structure
|
# version structure
|
||||||
|
|
||||||
|
import util
|
||||||
|
|
||||||
class Version:
|
class Version:
|
||||||
def __init__(self, verstring):
|
def __init__(self, verstring):
|
||||||
self.comps = verstring.split('.-')
|
self.comps = map(lambda x: int(x), util.multisplit(verstring,'.-'))
|
||||||
|
|
||||||
def pred(self,rhs,pred):
|
def pred(self,rhs,pred):
|
||||||
for i in range(0, len(comps)-1):
|
for i in range(0, len(comps)-1):
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ def run_all():
|
|||||||
import archivetests
|
import archivetests
|
||||||
import installdbtests
|
import installdbtests
|
||||||
import packagedbtests
|
import packagedbtests
|
||||||
|
import versiontests
|
||||||
|
|
||||||
alltests = unittest.TestSuite((
|
alltests = unittest.TestSuite((
|
||||||
specfiletests.suite,
|
specfiletests.suite,
|
||||||
contexttests.suite,
|
contexttests.suite,
|
||||||
fetchertests.suite,
|
fetchertests.suite,
|
||||||
archivetests.suite,
|
archivetests.suite,
|
||||||
|
versiontests.suite,
|
||||||
installdbtests.suite,
|
installdbtests.suite,
|
||||||
packagedbtests. suite
|
packagedbtests. suite
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user