From 9ce6a26db33b6f46865f0878bf950624ed52b738 Mon Sep 17 00:00:00 2001 From: Matthew Duggan Date: Mon, 18 Aug 2014 18:23:10 +0900 Subject: [PATCH] Add some tests for refcounts to check for leaks --- test/test_commit.py | 10 ++++++++++ test/test_remote.py | 9 +++++++++ test/test_repository.py | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/test/test_commit.py b/test/test_commit.py index f7a42b6..0ce5223 100644 --- a/test/test_commit.py +++ b/test/test_commit.py @@ -30,6 +30,7 @@ from __future__ import absolute_import from __future__ import unicode_literals import unittest +import sys from pygit2 import GIT_OBJ_COMMIT, Signature, Oid from . import utils @@ -46,6 +47,15 @@ COMMIT_SHA = '5fe808e8953c12735680c257f56600cb0de44b10' class CommitTest(utils.BareRepoTestCase): + def test_commit_refcount(self): + commit = self.repo[COMMIT_SHA] + start = sys.getrefcount(commit) + tree = commit.tree + del tree + end = sys.getrefcount(commit) + self.assertEqual(start, end) + + def test_read_commit(self): commit = self.repo[COMMIT_SHA] self.assertEqual(COMMIT_SHA, str(commit.id)) diff --git a/test/test_remote.py b/test/test_remote.py index 57814a3..aea1bb0 100644 --- a/test/test_remote.py +++ b/test/test_remote.py @@ -30,6 +30,7 @@ import unittest import pygit2 +import sys from pygit2 import Oid from . import utils @@ -163,6 +164,14 @@ class RepositoryTest(utils.RepoTestCase): self.assertEqual('http://example.com/test.git', self.repo.remotes[0].url) + def test_remote_refcount(self): + start = sys.getrefcount(self.repo) + remote = self.repo.remotes[0] + del remote + end = sys.getrefcount(self.repo) + + self.assertEqual(start, end) + def test_add_refspec(self): remote = self.repo.create_remote('test_add_refspec', REMOTE_URL) remote.add_push('refs/heads/*:refs/heads/test_refspec/*') diff --git a/test/test_repository.py b/test/test_repository.py index cda846c..53def2c 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -37,6 +37,7 @@ import unittest import tempfile import os from os.path import join, realpath +import sys # Import from pygit2 from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT @@ -150,6 +151,14 @@ class RepositoryTest(utils.BareRepoTestCase): commit.message) self.assertRaises(ValueError, self.repo.__getitem__, too_short_prefix) + def test_lookup_commit_refcount(self): + start = sys.getrefcount(self.repo) + commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10' + commit = self.repo[commit_sha] + del commit + end = sys.getrefcount(self.repo) + self.assertEqual(start, end) + def test_get_path(self): directory = realpath(self.repo.path) expected = realpath(self.repo_path)