[Zope3-checkins] CVS: Zope3/src/zope/fssync/tests - mockmetadata.py:1.1 test_fsmerger.py:1.3 test_merger.py:1.10

Guido van Rossum guido@python.org
Wed, 28 May 2003 09:48:17 -0400


Update of /cvs-repository/Zope3/src/zope/fssync/tests
In directory cvs.zope.org:/tmp/cvs-serv26450/tests

Modified Files:
	test_fsmerger.py test_merger.py 
Added Files:
	mockmetadata.py 
Log Message:
Refactoring: move MockMetadata to its own file.

=== Added File Zope3/src/zope/fssync/tests/mockmetadata.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Mock Metadata class used for testing.

$Id: mockmetadata.py,v 1.1 2003/05/28 13:48:16 gvanrossum Exp $
"""

import os

class MockMetadata(object):

    def __init__(self):
        self.database = {}

    def getentry(self, filename):
        key, filename = self.makekey(filename)
        if key not in self.database:
            self.database[key] = {}
        return self.database[key]

    def getnames(self, dirpath):
        dirkey, dirpath = self.makekey(dirpath)
        names = []
        for key in self.database:
            head, tail = os.path.split(key)
            if head == dirkey:
                names.append(tail)
        return names

    def flush(self):
        pass

    # These only exist for the test framework

    def makekey(self, path):
        path = os.path.realpath(path)
        key = os.path.normcase(path)
        return key, path

    def setmetadata(self, filename, metadata={}):
        key, filename = self.makekey(filename)
        if key not in self.database:
            self.database[key] = {"path": filename}
        self.database[key].update(metadata)

    def delmetadata(self, filename):
        key, filename = self.makekey(filename)
        if key in self.database:
            del self.database[key]

    def dump(self):
        return dict([(k, v) for (k, v) in self.database.iteritems() if v])


=== Zope3/src/zope/fssync/tests/test_fsmerger.py 1.2 => 1.3 ===
--- Zope3/src/zope/fssync/tests/test_fsmerger.py:1.2	Thu May 15 07:38:39 2003
+++ Zope3/src/zope/fssync/tests/test_fsmerger.py	Wed May 28 09:48:16 2003
@@ -25,49 +25,7 @@
 
 from zope.fssync.fsmerger import FSMerger
 
-class MockMetadata(object):
-
-    def __init__(self):
-        self.database = {}
-
-    def getentry(self, filename):
-        key, filename = self.makekey(filename)
-        if key not in self.database:
-            self.database[key] = {}
-        return self.database[key]
-
-    def getnames(self, dirpath):
-        dirkey, dirpath = self.makekey(dirpath)
-        names = []
-        for key in self.database:
-            head, tail = split(key)
-            if head == dirkey:
-                names.append(tail)
-        return names
-
-    def flush(self):
-        pass
-
-    # These only exist for the test framework
-
-    def makekey(self, path):
-        path = realpath(path)
-        key = normcase(path)
-        return key, path
-
-    def setmetadata(self, filename, metadata={}):
-        key, filename = self.makekey(filename)
-        if key not in self.database:
-            self.database[key] = {"path": filename}
-        self.database[key].update(metadata)
-
-    def delmetadata(self, filename):
-        key, filename = self.makekey(filename)
-        if key in self.database:
-            del self.database[key]
-
-    def dump(self):
-        return dict([(k, v) for (k, v) in self.database.iteritems() if v])
+from zope.fssync.tests.mockmetadata import MockMetadata
 
 class TestFSMerger(unittest.TestCase):
 


=== Zope3/src/zope/fssync/tests/test_merger.py 1.9 => 1.10 ===
--- Zope3/src/zope/fssync/tests/test_merger.py:1.9	Thu May 15 08:05:12 2003
+++ Zope3/src/zope/fssync/tests/test_merger.py	Wed May 28 09:48:16 2003
@@ -25,32 +25,7 @@
 
 from zope.fssync.merger import Merger
 
-class MockMetadatabase(object):
-
-    def __init__(self):
-        self.database = {}
-
-    def makekey(self, file):
-        file = realpath(file)
-        key = normcase(file)
-        return key, file
-
-    def getentry(self, file):
-        key, file = self.makekey(file)
-        if key not in self.database:
-            self.database[key] = {}
-        return self.database[key]
-
-    def setmetadata(self, file, metadata={}):
-        key, file = self.makekey(file)
-        if key not in self.database:
-            self.database[key] = {"path": file}
-        self.database[key].update(metadata)
-
-    def delmetadata(self, file):
-        key, file = self.makekey(file)
-        if key in self.database:
-            del self.database[key]
+from zope.fssync.tests.mockmetadata import MockMetadata
 
 added = {"flag": "added"}
 removed = {"flag": "removed"}
@@ -121,7 +96,7 @@
         local = self.addfile(localdata)
         orig = self.addfile(origdata)
         remote = self.addfile(remotedata)
-        md = MockMetadatabase()
+        md = MockMetadata()
         if localmetadata is not None:
             md.setmetadata(local, localmetadata)
         if remotemetadata is not None: