Пример #1
0
class GeogigDiffTest(unittest.TestCase):

    repo = testRepo()

    def getTempPath(self):
        return os.path.join(os.path.dirname(__file__), "temp", str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        dst = self.getTempPath()
        return self.repo.clone(dst)

    def testOldFeatureIsNone(self):
        diff = self.repo.log()[0].diff()[0]
        old = diff.oldobject()
        self.assertIsNotNone(old)
        self.assertEquals("parks/5", old.path)
        attrs = old.attributes
        self.assertEqual(15297.503295898438, attrs['area'])

    def testNewFeature(self):
        diff = self.repo.log()[0].diff()[0]
        new = diff.newobject()
        self.assertIsNotNone(new)
        self.assertEquals("parks/5", new.path)
        attrs = new.attributes
        self.assertEqual(15246.59765625, attrs['area'])
Пример #2
0
class GeogigTreeTest(unittest.TestCase):

    repo = testRepo()

    def getTempPath(self):
        return os.path.join(os.path.dirname(__file__), "temp",
                            str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        dst = self.getTempPath()
        return self.repo.clone(dst)

    def testExportShp(self):
        repo = self.getClonedRepo()
        exportPath = os.path.join(os.path.dirname(__file__), "temp",
                                  str(time.time()) + ".shp").replace(
                                      '\\', '/')
        tree = Tree(repo, geogig.HEAD, "parks")
        tree.exportshp(exportPath)
        self.assertTrue(os.path.exists(exportPath))

    def testFeatures(self):
        tree = Tree(self.repo, geogig.HEAD, "parks")
        features = tree.features
        self.assertEquals(5, len(features))

    def testFeatureType(self):
        tree = Tree(self.repo, geogig.HEAD, "parks")
        ftype = tree.featuretype
        self.assertEqual("DOUBLE", ftype["perimeter"])
        self.assertEqual("STRING", ftype["name"])
        self.assertEqual("MULTIPOLYGON", ftype["the_geom"])
Пример #3
0
class GeogigCommitTest(unittest.TestCase):

    repo = testRepo()

    def getTempPath(self):
        return os.path.join(os.path.dirname(__file__), "temp",
                            str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        dst = self.getTempPath()
        return self.repo.clone(dst)

    def testFromRef(self):
        ref = self.repo.head.ref
        commit = Commit.fromref(self.repo, ref)
        log = self.repo.log()
        headcommit = log[0]
        self.assertEqual(headcommit.ref, commit.ref)
        self.assertEqual(headcommit.committerdate, commit.committerdate)

    def testCommitDiff(self):
        log = self.repo.log()
        commit = log[0]
        diff = commit.diff()
        self.assertEquals(1, len(diff))
        self.assertEquals("parks/5", diff[0].path)
Пример #4
0
class GeogigCommitishTest(unittest.TestCase):

    repo = testRepo()

    def getTempPath(self):
        return os.path.join(os.path.dirname(__file__), "temp",
                            str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        dst = self.getTempPath()
        return self.repo.clone(dst)

    def testLog(self):
        commitish = Commitish(self.repo, geogig.HEAD)
        log = commitish.log()
        self.assertEquals(4, len(log))
        self.assertEquals("message_4", log[0].message)

    def testRootTreeListing(self):
        commitish = Commitish(self.repo, geogig.HEAD)
        trees = commitish.root.trees
        self.assertEquals(1, len(trees))
        self.assertEquals("parks", trees[0].path)
        entries = self.repo.log()
        id = self.repo.revparse(trees[0].ref)
        self.assertEquals(entries[0].commitid, id)

    def testCheckout(self):
        repo = self.getClonedRepo()
        branch = Commitish(repo, "conflicted")
        branch.checkout()
        self.assertEquals(repo.head.id, branch.id)
        master = Commitish(repo, geogig.MASTER)
        master.checkout()
        self.assertEquals(repo.head.id, master.id)

    def testDiff(self):
        commitish = Commitish(self.repo, geogig.HEAD)
        diff = commitish.diff()
        self.assertEquals(1, len(diff))
        self.assertEquals("parks/5", diff[0].path)

    def testDiffCaching(self):
        commitish = Commitish(self.repo, geogig.HEAD)
        diff = commitish.diff()
        self.assertEquals(diff, commitish._diff)
Пример #5
0
class GeogigRepositoryTest(unittest.TestCase):

    repo = testRepo()

    def getTempRepoPath(self):
        return os.path.join(os.path.dirname(__file__), "temp",
                            str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        dst = self.getTempRepoPath()
        return self.repo.clone(dst)

    def testCreateEmptyRepo(self):
        repoPath = self.getTempRepoPath()
        Repository(repoPath, init=True)

    def testRevParse(self):
        headid = self.repo.revparse(geogig.HEAD)
        entries = self.repo.log()
        self.assertEquals(entries[0].commitid, headid)

    def testHead(self):
        head = self.repo.head
        self.assertEquals("master", head.ref)

    def testIsDetached(self):
        repo = self.getClonedRepo()
        self.assertFalse(repo.isdetached())
        log = repo.log()
        repo.checkout(log[1].ref)
        self.assertTrue(repo.isdetached())

    def testRevParseWrongReference(self):
        try:
            self.repo.revparse("WrOnGReF")
            self.fail()
        except GeoGigException, e:
            pass
Пример #6
0
class GeogigFeatureTest(unittest.TestCase):

    repo = testRepo()

    def getTempPath(self):
        return os.path.join(os.path.dirname(__file__), "temp",
                            str(time.time())).replace('\\', '/')

    def getClonedRepo(self):
        src = self.repo.url
        dst = self.getTempPath()
        shutil.copytree(src, dst)
        return Repository(dst)

    def testExists(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/1")
        self.assertTrue(feature.exists())
        feature = Feature(self.repo, geogig.HEAD, "wrong/path")
        self.assertFalse(feature.exists())

    def testAttributes(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/1")
        data = feature.attributes
        self.assertEquals(8, len(data))
        self.assertEquals("Public", data["usage"])
        self.assertTrue("owner" in data)
        self.assertTrue("agency" in data)
        self.assertTrue("name" in data)
        self.assertTrue("parktype" in data)
        self.assertTrue("area" in data)
        self.assertTrue("perimeter" in data)
        self.assertTrue("the_geom" in data)
        self.assertTrue(isinstance(data["the_geom"], Geometry))

    def testDiff(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        featureB = Feature(self.repo, geogig.HEAD + "~1", "parks/5")
        diffs = feature.diff(featureB)
        self.assertTrue(2, len(diffs))
        areas = diffs["area"]
        self.assertEquals(15297.503295898438, areas[1])
        self.assertEquals(15246.59765625, areas[0])
        self.assertTrue("the_geom" in diffs)

    def testBlame(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        blame = feature.blame()
        self.assertEquals(8, len(blame))
        attrs = feature.attributes
        for k, v in blame.iteritems():
            self.assertTrue(v[0], attrs[k])

    def testFeatureType(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        ftype = feature.featuretype()
        self.assertTrue("owner" in ftype)
        self.assertTrue("agency" in ftype)
        self.assertTrue("name" in ftype)
        self.assertTrue("parktype" in ftype)
        self.assertTrue("area" in ftype)
        self.assertTrue("perimeter" in ftype)
        self.assertTrue("the_geom" in ftype)
        self.assertEquals("MULTIPOLYGON EPSG:4326", ftype['the_geom'])

    def testGeom(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        geom = feature.geom
        self.assertTrue(isinstance(geom, Geometry))

    def testGeomFieldName(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        name = feature.geomfieldname
        self.assertEquals("the_geom", name)

    def testNoGeom(self):
        feature = Feature(self.repo, geogig.HEAD, "parks/5")
        allattrs = feature.attributes
        attrs = feature.attributesnogeom
        self.assertEquals(len(allattrs), len(attrs) + 1)
        self.assertTrue("owner" in attrs)
        self.assertTrue("agency" in attrs)
        self.assertTrue("name" in attrs)
        self.assertTrue("parktype" in attrs)
        self.assertTrue("area" in attrs)
        self.assertTrue("perimeter" in attrs)
        self.assertFalse("the_geom" in attrs)