diff options
Diffstat (limited to 'git/test')
-rw-r--r-- | git/test/lib/asserts.py | 14 | ||||
-rw-r--r-- | git/test/lib/helper.py | 44 | ||||
-rw-r--r-- | git/test/performance/lib.py | 1 | ||||
-rw-r--r-- | git/test/performance/test_odb.py | 6 | ||||
-rw-r--r-- | git/test/performance/test_streams.py | 4 | ||||
-rw-r--r-- | git/test/test_commit.py | 2 | ||||
-rw-r--r-- | git/test/test_config.py | 38 | ||||
-rw-r--r-- | git/test/test_docs.py | 23 | ||||
-rw-r--r-- | git/test/test_exc.py | 14 | ||||
-rw-r--r-- | git/test/test_git.py | 4 | ||||
-rw-r--r-- | git/test/test_index.py | 61 | ||||
-rw-r--r-- | git/test/test_refs.py | 20 | ||||
-rw-r--r-- | git/test/test_remote.py | 22 | ||||
-rw-r--r-- | git/test/test_repo.py | 20 | ||||
-rw-r--r-- | git/test/test_submodule.py | 149 | ||||
-rw-r--r-- | git/test/test_tree.py | 19 | ||||
-rw-r--r-- | git/test/test_util.py | 122 |
17 files changed, 321 insertions, 242 deletions
diff --git a/git/test/lib/asserts.py b/git/test/lib/asserts.py index 9edc49e0..6f5ba714 100644 --- a/git/test/lib/asserts.py +++ b/git/test/lib/asserts.py @@ -8,18 +8,18 @@ import re import stat from nose.tools import ( - assert_equal, - assert_not_equal, - assert_raises, - raises, - assert_true, - assert_false + assert_equal, # @UnusedImport + assert_not_equal, # @UnusedImport + assert_raises, # @UnusedImport + raises, # @UnusedImport + assert_true, # @UnusedImport + assert_false # @UnusedImport ) try: from unittest.mock import patch except ImportError: - from mock import patch + from mock import patch # @NoMove @UnusedImport __all__ = ['assert_instance_of', 'assert_not_instance_of', 'assert_none', 'assert_not_none', diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index a85ac2fd..e92ce8b4 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -12,7 +12,8 @@ import tempfile import io import logging -from git import Repo, Remote, GitCommandError, Git +from functools import wraps + from git.util import rmtree from git.compat import string_types, is_win import textwrap @@ -30,6 +31,11 @@ __all__ = ( log = logging.getLogger('git.util') +#: We need an easy way to see if Appveyor TCs start failing, +#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy, +#: till then, we wish to hide them. +HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_KNOWN_ERRORS', True) + #{ Routines @@ -86,6 +92,7 @@ def with_rw_directory(func): """Create a temporary directory which can be written to, remove it if the test succeeds, but leave it otherwise to aid additional debugging""" + @wraps(func) def wrapper(self): path = tempfile.mktemp(prefix=func.__name__) os.mkdir(path) @@ -94,8 +101,8 @@ def with_rw_directory(func): try: return func(self, path) except Exception: - log.info.write("Test %s.%s failed, output is at %r\n", - type(self).__name__, func.__name__, path) + log.info("Test %s.%s failed, output is at %r\n", + type(self).__name__, func.__name__, path) keep = True raise finally: @@ -108,6 +115,8 @@ def with_rw_directory(func): if not keep: rmtree(path) + return wrapper + def with_rw_repo(working_tree_ref, bare=False): """ @@ -122,6 +131,7 @@ def with_rw_repo(working_tree_ref, bare=False): assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout" def argument_passer(func): + @wraps(func) def repo_creator(self): prefix = 'non_' if bare: @@ -155,13 +165,13 @@ def with_rw_repo(working_tree_ref, bare=False): # END rm test repo if possible # END cleanup # END rw repo creator - repo_creator.__name__ = func.__name__ return repo_creator # END argument passer return argument_passer def launch_git_daemon(temp_dir, ip, port): + from git import Git if is_win: ## On MINGW-git, daemon exists in .\Git\mingw64\libexec\git-core\, # but if invoked as 'git daemon', it detaches from parent `git` cmd, @@ -207,10 +217,12 @@ def with_rw_and_rw_remote_repo(working_tree_ref): See working dir info in with_rw_repo :note: We attempt to launch our own invocation of git-daemon, which will be shutdown at the end of the test. """ + from git import Remote, GitCommandError assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout" def argument_passer(func): + @wraps(func) def remote_repo_creator(self): remote_repo_dir = _mktemp("remote_repo_%s" % func.__name__) repo_dir = _mktemp("remote_clone_non_bare_repo") @@ -225,16 +237,13 @@ def with_rw_and_rw_remote_repo(working_tree_ref): rw_remote_repo.daemon_export = True # this thing is just annoying ! - crw = rw_remote_repo.config_writer() - section = "daemon" - try: - crw.add_section(section) - except Exception: - pass - crw.set(section, "receivepack", True) - # release lock - crw.release() - del(crw) + with rw_remote_repo.config_writer() as crw: + section = "daemon" + try: + crw.add_section(section) + except Exception: + pass + crw.set(section, "receivepack", True) # initialize the remote - first do it as local remote and pull, then # we change the url to point to the daemon. The daemon should be started @@ -243,7 +252,8 @@ def with_rw_and_rw_remote_repo(working_tree_ref): d_remote.fetch() remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir) - d_remote.config_writer.set('url', remote_repo_url) + with d_remote.config_writer as cw: + cw.set('url', remote_repo_url) temp_dir = osp(_mktemp()) gd = launch_git_daemon(temp_dir, '127.0.0.1', GIT_DAEMON_PORT) @@ -319,10 +329,9 @@ def with_rw_and_rw_remote_repo(working_tree_ref): gd.proc.wait() # END cleanup # END bare repo creator - remote_repo_creator.__name__ = func.__name__ return remote_repo_creator # END remote repo creator - # END argument parsser + # END argument parser return argument_passer @@ -358,6 +367,7 @@ class TestBase(TestCase): Dynamically add a read-only repository to our actual type. This way each test type has its own repository """ + from git import Repo import gc gc.collect() cls.rorepo = Repo(GIT_REPO) diff --git a/git/test/performance/lib.py b/git/test/performance/lib.py index eebbfd76..0c4c20a4 100644 --- a/git/test/performance/lib.py +++ b/git/test/performance/lib.py @@ -19,6 +19,7 @@ from git.util import rmtree #{ Invvariants k_env_git_repo = "GIT_PYTHON_TEST_GIT_REPO_BASE" + #} END invariants diff --git a/git/test/performance/test_odb.py b/git/test/performance/test_odb.py index 9abe2d42..6f07a615 100644 --- a/git/test/performance/test_odb.py +++ b/git/test/performance/test_odb.py @@ -5,7 +5,8 @@ import sys from time import time from unittest.case import skipIf -from git.compat import is_win, PY3 +from git.compat import PY3 +from git.test.lib.helper import HIDE_WINDOWS_KNOWN_ERRORS from .lib import ( TestBigRepoR @@ -14,7 +15,8 @@ from .lib import ( class TestObjDBPerformance(TestBigRepoR): - @skipIf(is_win and PY3, "FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly") + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and PY3, + "FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly") def test_random_access(self): results = [["Iterate Commits"], ["Iterate Blobs"], ["Retrieve Blob Data"]] for repo in (self.gitrorepo, self.puregitrorepo): diff --git a/git/test/performance/test_streams.py b/git/test/performance/test_streams.py index 8194547c..42cbade5 100644 --- a/git/test/performance/test_streams.py +++ b/git/test/performance/test_streams.py @@ -120,7 +120,7 @@ class TestObjDBPerformance(TestBigRepoR): # read all st = time() - s, t, size, data = rwrepo.git.get_object_data(gitsha) + hexsha, typename, size, data = rwrepo.git.get_object_data(gitsha) # @UnusedVariable gelapsed_readall = time() - st print("Read %i KiB of %s data at once using git-cat-file in %f s ( %f Read KiB / s)" % (size_kib, desc, gelapsed_readall, size_kib / gelapsed_readall), file=sys.stderr) @@ -131,7 +131,7 @@ class TestObjDBPerformance(TestBigRepoR): # read chunks st = time() - s, t, size, stream = rwrepo.git.stream_object_data(gitsha) + hexsha, typename, size, stream = rwrepo.git.stream_object_data(gitsha) # @UnusedVariable while True: data = stream.read(cs) if len(data) < cs: diff --git a/git/test/test_commit.py b/git/test/test_commit.py index 66d988a3..fd9777fb 100644 --- a/git/test/test_commit.py +++ b/git/test/test_commit.py @@ -123,7 +123,7 @@ class TestCommit(TestBase): check_entries(stats.total) assert "files" in stats.total - for filepath, d in stats.files.items(): + for filepath, d in stats.files.items(): # @UnusedVariable check_entries(d) # END for each stated file diff --git a/git/test/test_config.py b/git/test/test_config.py index 154aaa24..32873f24 100644 --- a/git/test/test_config.py +++ b/git/test/test_config.py @@ -60,7 +60,8 @@ class TestBase(TestCase): self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path(filename)).getvalue()) # creating an additional config writer must fail due to exclusive access - self.failUnlessRaises(IOError, GitConfigParser, file_obj, read_only=False) + with self.assertRaises(IOError): + GitConfigParser(file_obj, read_only=False) # should still have a lock and be able to make changes assert w_config._lock._has_lock() @@ -91,18 +92,21 @@ class TestBase(TestCase): @with_rw_directory def test_lock_reentry(self, rw_dir): fpl = os.path.join(rw_dir, 'l') - with GitConfigParser(fpl, read_only=False) as gcp: - gcp.set_value('include', 'some_value', 'a') + gcp = GitConfigParser(fpl, read_only=False) + with gcp as cw: + cw.set_value('include', 'some_value', 'a') # entering again locks the file again... with gcp as cw: cw.set_value('include', 'some_other_value', 'b') # ...so creating an additional config writer must fail due to exclusive access - self.failUnlessRaises(IOError, GitConfigParser, fpl, read_only=False) + with self.assertRaises(IOError): + GitConfigParser(fpl, read_only=False) # but work when the lock is removed with GitConfigParser(fpl, read_only=False): assert os.path.exists(fpl) # reentering with an existing lock must fail due to exclusive access - self.failUnlessRaises(IOError, gcp.__enter__) + with self.assertRaises(IOError): + gcp.__enter__() def test_multi_line_config(self): file_obj = self._to_memcache(fixture_path("git_config_with_comments")) @@ -144,10 +148,13 @@ class TestBase(TestCase): assert "\n" not in val # writing must fail - self.failUnlessRaises(IOError, r_config.set, section, option, None) - self.failUnlessRaises(IOError, r_config.remove_option, section, option) + with self.assertRaises(IOError): + r_config.set(section, option, None) + with self.assertRaises(IOError): + r_config.remove_option(section, option) # END for each option - self.failUnlessRaises(IOError, r_config.remove_section, section) + with self.assertRaises(IOError): + r_config.remove_section(section) # END for each section assert num_sections and num_options assert r_config._is_initialized is True @@ -157,7 +164,8 @@ class TestBase(TestCase): assert r_config.get_value("doesnt", "exist", default) == default # it raises if there is no default though - self.failUnlessRaises(cp.NoSectionError, r_config.get_value, "doesnt", "exist") + with self.assertRaises(cp.NoSectionError): + r_config.get_value("doesnt", "exist") @with_rw_directory def test_config_include(self, rw_dir): @@ -206,7 +214,8 @@ class TestBase(TestCase): write_test_value(cw, tv) with GitConfigParser(fpa, read_only=True) as cr: - self.failUnlessRaises(cp.NoSectionError, check_test_value, cr, tv) + with self.assertRaises(cp.NoSectionError): + check_test_value(cr, tv) # But can make it skip includes alltogether, and thus allow write-backs with GitConfigParser(fpa, read_only=False, merge_includes=False) as cw: @@ -218,8 +227,10 @@ class TestBase(TestCase): def test_rename(self): file_obj = self._to_memcache(fixture_path('git_config')) with GitConfigParser(file_obj, read_only=False, merge_includes=False) as cw: - self.failUnlessRaises(ValueError, cw.rename_section, "doesntexist", "foo") - self.failUnlessRaises(ValueError, cw.rename_section, "core", "include") + with self.assertRaises(ValueError): + cw.rename_section("doesntexist", "foo") + with self.assertRaises(ValueError): + cw.rename_section("core", "include") nn = "bee" assert cw.rename_section('core', nn) is cw @@ -237,4 +248,5 @@ class TestBase(TestCase): assert cr.get_value('core', 'filemode'), "Should read keys with values" - self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui') + with self.assertRaises(cp.NoOptionError): + cr.get_value('color', 'ui') diff --git a/git/test/test_docs.py b/git/test/test_docs.py index 8a2dff0f..e2bfcb21 100644 --- a/git/test/test_docs.py +++ b/git/test/test_docs.py @@ -16,6 +16,9 @@ class Tutorials(TestBase): import gc gc.collect() + # @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, + # "FIXME: helper.wrapper fails with: PermissionError: [WinError 5] Access is denied: " + # "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501 @with_rw_directory def test_init_repo_object(self, rw_dir): # [1-test_init_repo_object] @@ -36,8 +39,8 @@ class Tutorials(TestBase): # [3-test_init_repo_object] repo.config_reader() # get a config reader for read-only access - cw = repo.config_writer() # get a config writer to change configuration - cw.release() # call release() to be sure changes are written and locks are released + with repo.config_writer(): # get a config writer to change configuration + pass # call release() to be sure changes are written and locks are released # ![3-test_init_repo_object] # [4-test_init_repo_object] @@ -67,7 +70,8 @@ class Tutorials(TestBase): # heads, tags and references # heads are branches in git-speak # [8-test_init_repo_object] - self.assertEqual(repo.head.ref, repo.heads.master) # head is a sym-ref pointing to master + self.assertEqual(repo.head.ref, repo.heads.master, # head is a sym-ref pointing to master + "It's ok if TC not running from `master`.") self.assertEqual(repo.tags['0.3.5'], repo.tag('refs/tags/0.3.5')) # you can access tags in various ways too self.assertEqual(repo.refs.master, repo.heads['master']) # .refs provides all refs, ie heads ... @@ -239,9 +243,9 @@ class Tutorials(TestBase): # [8-test_references_and_objects] hc = repo.head.commit hct = hc.tree - hc != hct - hc != repo.tags[0] - hc == repo.head.reference.commit + hc != hct # @NoEffect + hc != repo.tags[0] # @NoEffect + hc == repo.head.reference.commit # @NoEffect # ![8-test_references_and_objects] # [9-test_references_and_objects] @@ -344,7 +348,7 @@ class Tutorials(TestBase): # The index contains all blobs in a flat list assert len(list(index.iter_blobs())) == len([o for o in repo.head.commit.tree.traverse() if o.type == 'blob']) # Access blob objects - for (path, stage), entry in index.entries.items(): + for (path, stage), entry in index.entries.items(): # @UnusedVariable pass new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name') open(new_file_path, 'w').close() @@ -394,9 +398,8 @@ class Tutorials(TestBase): # [26-test_references_and_objects] assert origin.url == repo.remotes.origin.url - cw = origin.config_writer - cw.set("pushurl", "other_url") - cw.release() + with origin.config_writer as cw: + cw.set("pushurl", "other_url") # Please note that in python 2, writing origin.config_writer.set(...) is totally safe. # In py3 __del__ calls can be delayed, thus not writing changes in time. diff --git a/git/test/test_exc.py b/git/test/test_exc.py index 7e6b023e..33f44034 100644 --- a/git/test/test_exc.py +++ b/git/test/test_exc.py @@ -29,13 +29,13 @@ _cmd_argvs = ( ('θνιψοδε', 'κι', 'αλλα', 'non-unicode', 'args'), ) _causes_n_substrings = ( - (None, None), # noqa: E241 - (7, "exit code(7)"), # noqa: E241 - ('Some string', "'Some string'"), # noqa: E241 - ('παλιο string', "'παλιο string'"), # noqa: E241 - (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 - (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 - (object(), "<object object at "), # noqa: E241 + (None, None), # noqa: E241 @IgnorePep8 + (7, "exit code(7)"), # noqa: E241 @IgnorePep8 + ('Some string', "'Some string'"), # noqa: E241 @IgnorePep8 + ('παλιο string', "'παλιο string'"), # noqa: E241 @IgnorePep8 + (Exception("An exc."), "Exception('An exc.')"), # noqa: E241 @IgnorePep8 + (Exception("Κακια exc."), "Exception('Κακια exc.')"), # noqa: E241 @IgnorePep8 + (object(), "<object object at "), # noqa: E241 @IgnorePep8 ) _streams_n_substrings = (None, 'steram', 'ομορφο stream', ) diff --git a/git/test/test_git.py b/git/test/test_git.py index 94614cd1..58ee8e9c 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -121,7 +121,7 @@ class TestGit(TestBase): # read data - have to read it in one large chunk size = int(obj_info.split()[2]) - data = g.stdout.read(size) + g.stdout.read(size) g.stdout.read(1) # now we should be able to read a new object @@ -131,7 +131,7 @@ class TestGit(TestBase): # same can be achived using the respective command functions hexsha, typename, size = self.git.get_object_header(hexsha) - hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) + hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) # @UnusedVariable self.assertEqual(typename, typename_two) self.assertEqual(size, size_two) diff --git a/git/test/test_index.py b/git/test/test_index.py index 1ffbe9e2..34014064 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -5,17 +5,16 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -from git.test.lib import ( - TestBase, - fixture_path, - fixture, - with_rw_repo -) -from git.util import Actor, rmtree -from git.exc import ( - HookExecutionError, - InvalidGitRepositoryError +from io import BytesIO +import os +from stat import ( + S_ISLNK, + ST_MODE ) +import sys +import tempfile +from unittest.case import skipIf + from git import ( IndexFile, Repo, @@ -28,24 +27,27 @@ from git import ( CheckoutError, ) from git.compat import string_types, is_win -from gitdb.util import hex_to_bin -import os -import sys -import tempfile -from stat import ( - S_ISLNK, - ST_MODE +from git.exc import ( + HookExecutionError, + InvalidGitRepositoryError ) - -from io import BytesIO -from gitdb.base import IStream -from git.objects import Blob +from git.index.fun import hook_path from git.index.typ import ( BaseIndexEntry, IndexEntry ) -from git.index.fun import hook_path +from git.objects import Blob +from git.test.lib import ( + TestBase, + fixture_path, + fixture, + with_rw_repo +) +from git.test.lib.helper import HIDE_WINDOWS_KNOWN_ERRORS from git.test.lib import with_rw_directory +from git.util import Actor, rmtree +from gitdb.base import IStream +from gitdb.util import hex_to_bin class TestIndex(TestBase): @@ -56,7 +58,7 @@ class TestIndex(TestBase): def _assert_fprogress(self, entries): self.assertEqual(len(entries), len(self._fprogress_map)) - for path, call_count in self._fprogress_map.items(): + for path, call_count in self._fprogress_map.items(): # @UnusedVariable self.assertEqual(call_count, 2) # END for each item in progress map self._reset_progress() @@ -186,7 +188,7 @@ class TestIndex(TestBase): # test BlobFilter prefix = 'lib/git' - for stage, blob in base_index.iter_blobs(BlobFilter([prefix])): + for stage, blob in base_index.iter_blobs(BlobFilter([prefix])): # @UnusedVariable assert blob.path.startswith(prefix) # writing a tree should fail with an unmerged index @@ -410,10 +412,9 @@ class TestIndex(TestBase): uname = u"Thomas Müller" umail = "sd@company.com" - writer = rw_repo.config_writer() - writer.set_value("user", "name", uname) - writer.set_value("user", "email", umail) - writer.release() + with rw_repo.config_writer() as writer: + writer.set_value("user", "name", uname) + writer.set_value("user", "email", umail) self.assertEqual(writer.get_value("user", "name"), uname) # remove all of the files, provide a wild mix of paths, BaseIndexEntries, @@ -821,6 +822,10 @@ class TestIndex(TestBase): asserted = True assert asserted, "Adding using a filename is not correctly asserted." + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and sys.version_info[:2] == (2, 7), r""" + FIXME: File "C:\projects\gitpython\git\util.py", line 125, in to_native_path_linux + return path.replace('\\', '/') + UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)""") @with_rw_directory def test_add_utf8P_path(self, rw_dir): # NOTE: fp is not a Unicode object in python 2 (which is the source of the problem) diff --git a/git/test/test_refs.py b/git/test/test_refs.py index 9816fb50..43f1dcc7 100644 --- a/git/test/test_refs.py +++ b/git/test/test_refs.py @@ -101,15 +101,13 @@ class TestRefs(TestBase): assert prev_object == cur_object # represent the same git object assert prev_object is not cur_object # but are different instances - writer = head.config_writer() - tv = "testopt" - writer.set_value(tv, 1) - assert writer.get_value(tv) == 1 - writer.release() + with head.config_writer() as writer: + tv = "testopt" + writer.set_value(tv, 1) + assert writer.get_value(tv) == 1 assert head.config_reader().get_value(tv) == 1 - writer = head.config_writer() - writer.remove_option(tv) - writer.release() + with head.config_writer() as writer: + writer.remove_option(tv) # after the clone, we might still have a tracking branch setup head.set_tracking_branch(None) @@ -175,7 +173,7 @@ class TestRefs(TestBase): def test_orig_head(self): assert type(self.rorepo.head.orig_head()) == SymbolicReference - + @with_rw_repo('0.1.6') def test_head_checkout_detached_head(self, rw_repo): res = rw_repo.remotes.origin.refs.master.checkout() @@ -282,7 +280,7 @@ class TestRefs(TestBase): # tag ref tag_name = "5.0.2" - light_tag = TagReference.create(rw_repo, tag_name) + TagReference.create(rw_repo, tag_name) self.failUnlessRaises(GitCommandError, TagReference.create, rw_repo, tag_name) light_tag = TagReference.create(rw_repo, tag_name, "HEAD~1", force=True) assert isinstance(light_tag, TagReference) @@ -442,7 +440,7 @@ class TestRefs(TestBase): self.failUnlessRaises(OSError, SymbolicReference.create, rw_repo, symref_path, cur_head.reference.commit) # it works if the new ref points to the same reference - SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path + SymbolicReference.create(rw_repo, symref.path, symref.reference).path == symref.path # @NoEffect SymbolicReference.delete(rw_repo, symref) # would raise if the symref wouldn't have been deletedpbl symref = SymbolicReference.create(rw_repo, symref_path, cur_head.reference) diff --git a/git/test/test_remote.py b/git/test/test_remote.py index b99e49cf..7b52ccce 100644 --- a/git/test/test_remote.py +++ b/git/test/test_remote.py @@ -90,7 +90,7 @@ class TestRemoteProgress(RemoteProgress): assert self._stages_per_op # must have seen all stages - for op, stages in self._stages_per_op.items(): + for op, stages in self._stages_per_op.items(): # @UnusedVariable assert stages & self.STAGE_MASK == self.STAGE_MASK # END for each op/stage @@ -267,7 +267,8 @@ class TestRemote(TestBase): # put origin to git-url other_origin = other_repo.remotes.origin - other_origin.config_writer.set("url", remote_repo_url) + with other_origin.config_writer as cw: + cw.set("url", remote_repo_url) # it automatically creates alternates as remote_repo is shared as well. # It will use the transport though and ignore alternates when fetching # assert not other_repo.alternates # this would fail @@ -331,7 +332,7 @@ class TestRemote(TestBase): # push new tags progress = TestRemoteProgress() to_be_updated = "my_tag.1.0RV" - new_tag = TagReference.create(rw_repo, to_be_updated) + new_tag = TagReference.create(rw_repo, to_be_updated) # @UnusedVariable other_tag = TagReference.create(rw_repo, "my_obj_tag.2.1aRV", message="my message") res = remote.push(progress=progress, tags=True) assert res[-1].flags & PushInfo.NEW_TAG @@ -416,13 +417,12 @@ class TestRemote(TestBase): self.failUnlessRaises(IOError, reader.set, opt, "test") # change value - writer = remote.config_writer - new_val = "myval" - writer.set(opt, new_val) - assert writer.get(opt) == new_val - writer.set(opt, val) - assert writer.get(opt) == val - del(writer) + with remote.config_writer as writer: + new_val = "myval" + writer.set(opt, new_val) + assert writer.get(opt) == new_val + writer.set(opt, val) + assert writer.get(opt) == val assert getattr(remote, opt) == val # END for each default option key @@ -432,7 +432,7 @@ class TestRemote(TestBase): assert remote.rename(other_name) == remote assert prev_name != remote.name # multiple times - for time in range(2): + for _ in range(2): assert remote.rename(prev_name).name == prev_name # END for each rename ( back to prev_name ) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index ae2bf2f0..1d537e93 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -7,11 +7,11 @@ import glob from io import BytesIO import itertools -import functools as fnt import os import pickle import sys import tempfile +from unittest.case import skipIf from git import ( InvalidGitRepositoryError, @@ -50,13 +50,14 @@ from git.test.lib import ( assert_true, raises ) +from git.test.lib.helper import HIDE_WINDOWS_KNOWN_ERRORS from git.test.lib import with_rw_directory from git.util import join_path_native, rmtree, rmfile from gitdb.util import bin_to_hex from nose import SkipTest +import functools as fnt import os.path as osp -from unittest.case import skipIf def iter_flatten(lol): @@ -486,7 +487,7 @@ class TestRepo(TestBase): @with_rw_directory def test_tilde_and_env_vars_in_repo_path(self, rw_dir): - ph = os.environ['HOME'] + ph = os.environ.get('HOME') try: os.environ['HOME'] = rw_dir Repo.init(os.path.join('~', 'test.git'), bare=True) @@ -494,8 +495,9 @@ class TestRepo(TestBase): os.environ['FOO'] = rw_dir Repo.init(os.path.join('$FOO', 'test.git'), bare=True) finally: - os.environ['HOME'] = ph - del os.environ['FOO'] + if ph: + os.environ['HOME'] = ph + del os.environ['FOO'] # end assure HOME gets reset to what it was def test_git_cmd(self): @@ -795,7 +797,8 @@ class TestRepo(TestBase): git_file_repo = Repo(rwrepo.working_tree_dir) self.assertEqual(os.path.abspath(git_file_repo.git_dir), real_path_abs) - @skipIf(is_win and PY3, "FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly") + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and PY3, + "FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly") def test_file_handle_leaks(self): def last_commit(repo, rev, path): commit = next(repo.iter_commits(rev, path, max_count=1)) @@ -806,7 +809,7 @@ class TestRepo(TestBase): # And we expect to set max handles to a low value, like 64 # You should set ulimit -n X, see .travis.yml # The loops below would easily create 500 handles if these would leak (4 pipes + multiple mapped files) - for i in range(64): + for _ in range(64): for repo_type in (GitCmdObjectDB, GitDB): repo = Repo(self.rorepo.working_tree_dir, odbt=repo_type) last_commit(repo, 'master', 'git/test/test_base.py') @@ -894,6 +897,9 @@ class TestRepo(TestBase): for i, j in itertools.permutations([c1, 'ffffff', ''], r=2): self.assertRaises(GitCommandError, repo.is_ancestor, i, j) + # @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, + # "FIXME: helper.wrapper fails with: PermissionError: [WinError 5] Access is denied: " + # "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501 @with_rw_directory def test_work_tree_unsupported(self, rw_dir): git = Git(rw_dir) diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index bfa0379d..46928f51 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -1,35 +1,36 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -import sys import os +import sys +from unittest.case import skipIf import git - -from git.test.lib import ( - TestBase, - with_rw_repo -) -from git.test.lib import with_rw_directory +from git.compat import string_types, is_win from git.exc import ( InvalidGitRepositoryError, RepositoryDirtyError ) from git.objects.submodule.base import Submodule from git.objects.submodule.root import RootModule, RootUpdateProgress -from git.util import to_native_path_linux, join_path_native -from git.compat import string_types, is_win from git.repo.fun import ( find_git_dir, touch ) -from unittest.case import skipIf +from git.test.lib import ( + TestBase, + with_rw_repo +) +from git.test.lib import with_rw_directory +from git.test.lib.helper import HIDE_WINDOWS_KNOWN_ERRORS +from git.util import to_native_path_linux, join_path_native + # Change the configuration if possible to prevent the underlying memory manager # to keep file handles open. On windows we get problems as they are not properly # closed due to mmap bugs on windows (as it appears) if is_win: try: - import smmap.util + import smmap.util # @UnusedImport smmap.util.MapRegion._test_read_into_memory = True except ImportError: sys.stderr.write("The submodule tests will fail as some files cannot be removed due to open file handles.\n") @@ -97,28 +98,32 @@ class TestSubmodule(TestBase): # force it to reread its information del(smold._url) - smold.url == sm.url + smold.url == sm.url # @NoEffect # test config_reader/writer methods sm.config_reader() new_smclone_path = None # keep custom paths for later new_csmclone_path = None # if rwrepo.bare: - self.failUnlessRaises(InvalidGitRepositoryError, sm.config_writer) + with self.assertRaises(InvalidGitRepositoryError): + with sm.config_writer() as cw: + pass else: - writer = sm.config_writer() - # for faster checkout, set the url to the local path - new_smclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path)) - writer.set_value('url', new_smclone_path) - writer.release() - assert sm.config_reader().get_value('url') == new_smclone_path - assert sm.url == new_smclone_path + with sm.config_writer() as writer: + # for faster checkout, set the url to the local path + new_smclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path)) + writer.set_value('url', new_smclone_path) + writer.release() + assert sm.config_reader().get_value('url') == new_smclone_path + assert sm.url == new_smclone_path # END handle bare repo smold.config_reader() # cannot get a writer on historical submodules if not rwrepo.bare: - self.failUnlessRaises(ValueError, smold.config_writer) + with self.assertRaises(ValueError): + with smold.config_writer(): + pass # END handle bare repo # make the old into a new - this doesn't work as the name changed @@ -209,9 +214,8 @@ class TestSubmodule(TestBase): # adjust the path of the submodules module to point to the local destination new_csmclone_path = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path, csm.path)) - writer = csm.config_writer() - writer.set_value('url', new_csmclone_path) - writer.release() + with csm.config_writer() as writer: + writer.set_value('url', new_csmclone_path) assert csm.url == new_csmclone_path # dry-run does nothing @@ -224,7 +228,7 @@ class TestSubmodule(TestBase): assert csm.module_exists() # tracking branch once again - csm.module().head.ref.tracking_branch() is not None + csm.module().head.ref.tracking_branch() is not None # @NoEffect # this flushed in a sub-submodule assert len(list(rwrepo.iter_submodules())) == 2 @@ -273,9 +277,8 @@ class TestSubmodule(TestBase): # module() is supposed to point to gitdb, which has a child-submodule whose URL is still pointing # to github. To save time, we will change it to csm.set_parent_commit(csm.repo.head.commit) - cw = csm.config_writer() - cw.set_value('url', self._small_repo_url()) - cw.release() + with csm.config_writer() as cw: + cw.set_value('url', self._small_repo_url()) csm.repo.index.commit("adjusted URL to point to local source, instead of the internet") # We have modified the configuration, hence the index is dirty, and the @@ -283,12 +286,10 @@ class TestSubmodule(TestBase): # NOTE: As we did a few updates in the meanwhile, the indices were reset # Hence we create some changes csm.set_parent_commit(csm.repo.head.commit) - writer = sm.config_writer() - writer.set_value("somekey", "somevalue") - writer.release() - writer = csm.config_writer() - writer.set_value("okey", "ovalue") - writer.release() + with sm.config_writer() as writer: + writer.set_value("somekey", "somevalue") + with csm.config_writer() as writer: + writer.set_value("okey", "ovalue") self.failUnlessRaises(InvalidGitRepositoryError, sm.remove) # if we remove the dirty index, it would work sm.module().index.reset() @@ -317,8 +318,8 @@ class TestSubmodule(TestBase): # forcibly delete the child repository prev_count = len(sm.children()) self.failUnlessRaises(ValueError, csm.remove, force=True) - # We removed sm, which removed all submodules. Howver, the instance we have - # still points to the commit prior to that, where it still existed + # We removed sm, which removed all submodules. However, the instance we + # have still points to the commit prior to that, where it still existed csm.set_parent_commit(csm.repo.commit(), check=False) assert not csm.exists() assert not csm.module_exists() @@ -417,9 +418,10 @@ class TestSubmodule(TestBase): # Error if there is no submodule file here self.failUnlessRaises(IOError, Submodule._config_parser, rwrepo, rwrepo.commit(self.k_no_subm_tag), True) - @skipIf(is_win, "FIXME: fails with: PermissionError: [WinError 32] The process cannot access the file because" - "it is being used by another process: " - "'C:\\Users\\ankostis\\AppData\\Local\\Temp\\tmp95c3z83bnon_bare_test_base_rw\\git\\ext\\gitdb\\gitdb\\ext\\smmap'") # noqa E501 + # @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, + # "FIXME: fails with: PermissionError: [WinError 32] The process cannot access the file because" + # "it is being used by another process: " + # "'C:\\Users\\ankostis\\AppData\\Local\\Temp\\tmp95c3z83bnon_bare_test_base_rw\\git\\ext\\gitdb\\gitdb\\ext\\smmap'") # noqa E501 @with_rw_repo(k_subm_current) def test_base_rw(self, rwrepo): self._do_base_tests(rwrepo) @@ -428,6 +430,11 @@ class TestSubmodule(TestBase): def test_base_bare(self, rwrepo): self._do_base_tests(rwrepo) + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and sys.version_info[:2] == (3, 5), """ + File "C:\projects\gitpython\git\cmd.py", line 559, in execute + raise GitCommandNotFound(command, err) + git.exc.GitCommandNotFound: Cmd('git') not found due to: OSError('[WinError 6] The handle is invalid') + cmdline: git clone -n --shared -v C:\projects\gitpython\.git Users\appveyor\AppData\Local\Temp\1\tmplyp6kr_rnon_bare_test_root_module""") # noqa E501 @with_rw_repo(k_subm_current, bare=False) def test_root_module(self, rwrepo): # Can query everything without problems @@ -445,8 +452,8 @@ class TestSubmodule(TestBase): assert len(rm.list_items(rm.module())) == 1 rm.config_reader() - w = rm.config_writer() - w.release() + with rm.config_writer(): + pass # deep traversal gitdb / async rsmsp = [sm.path for sm in rm.traverse()] @@ -471,9 +478,8 @@ class TestSubmodule(TestBase): assert not sm.module_exists() # was never updated after rwrepo's clone # assure we clone from a local source - writer = sm.config_writer() - writer.set_value('url', to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path))) - writer.release() + with sm.config_writer() as writer: + writer.set_value('url', to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, sm.path))) # dry-run does nothing sm.update(recursive=False, dry_run=True, progress=prog) @@ -481,9 +487,8 @@ class TestSubmodule(TestBase): sm.update(recursive=False) assert sm.module_exists() - writer = sm.config_writer() - writer.set_value('path', fp) # change path to something with prefix AFTER url change - writer.release() + with sm.config_writer() as writer: + writer.set_value('path', fp) # change path to something with prefix AFTER url change # update fails as list_items in such a situations cannot work, as it cannot # find the entry at the changed path @@ -570,9 +575,8 @@ class TestSubmodule(TestBase): # repository at the different url nsm.set_parent_commit(csmremoved) nsmurl = to_native_path_linux(join_path_native(self.rorepo.working_tree_dir, rsmsp[0])) - writer = nsm.config_writer() - writer.set_value('url', nsmurl) - writer.release() + with nsm.config_writer() as writer: + writer.set_value('url', nsmurl) csmpathchange = rwrepo.index.commit("changed url") nsm.set_parent_commit(csmpathchange) @@ -602,9 +606,8 @@ class TestSubmodule(TestBase): nsmm = nsm.module() prev_commit = nsmm.head.commit for branch in ("some_virtual_branch", cur_branch.name): - writer = nsm.config_writer() - writer.set_value(Submodule.k_head_option, git.Head.to_full_path(branch)) - writer.release() + with nsm.config_writer() as writer: + writer.set_value(Submodule.k_head_option, git.Head.to_full_path(branch)) csmbranchchange = rwrepo.index.commit("changed branch to %s" % branch) nsm.set_parent_commit(csmbranchchange) # END for each branch to change @@ -632,9 +635,8 @@ class TestSubmodule(TestBase): assert nsm.exists() and nsm.module_exists() and len(nsm.children()) >= 1 # assure we pull locally only nsmc = nsm.children()[0] - writer = nsmc.config_writer() - writer.set_value('url', subrepo_url) - writer.release() + with nsmc.config_writer() as writer: + writer.set_value('url', subrepo_url) rm.update(recursive=True, progress=prog, dry_run=True) # just to run the code rm.update(recursive=True, progress=prog) @@ -726,6 +728,9 @@ class TestSubmodule(TestBase): assert commit_sm.binsha == sm_too.binsha assert sm_too.binsha != sm.binsha + # @skipIf(HIDE_WINDOWS_KNOWN_ERRORS, + # "FIXME: helper.wrapper fails with: PermissionError: [WinError 5] Access is denied: " + # "'C:\\Users\\appveyor\\AppData\\Local\\Temp\\1\\test_work_tree_unsupportedryfa60di\\master_repo\\.git\\objects\\pack\\pack-bc9e0787aef9f69e1591ef38ea0a6f566ec66fe3.idx") # noqa E501 @with_rw_directory def test_git_submodule_compatibility(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) @@ -783,8 +788,8 @@ class TestSubmodule(TestBase): rsm = parent.submodule_update() assert_exists(sm) assert_exists(csm) - csm_writer = csm.config_writer().set_value('url', 'bar') - csm_writer.release() + with csm.config_writer().set_value('url', 'bar'): + pass csm.repo.index.commit("Have to commit submodule change for algorithm to pick it up") assert csm.url == 'bar' @@ -802,6 +807,24 @@ class TestSubmodule(TestBase): # end for each dry-run mode @with_rw_directory + def test_remove_norefs(self, rwdir): + parent = git.Repo.init(os.path.join(rwdir, 'parent')) + sm_name = 'mymodules/myname' + sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url()) + assert sm.exists() + + parent.index.commit("Added submodule") + + assert sm.repo is parent # yoh was surprised since expected sm repo!! + # so created a new instance for submodule + smrepo = git.Repo(os.path.join(rwdir, 'parent', sm.path)) + # Adding a remote without fetching so would have no references + smrepo.create_remote('special', 'git@server-shouldnotmatter:repo.git') + # And we should be able to remove it just fine + sm.remove() + assert not sm.exists() + + @with_rw_directory def test_rename(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) sm_name = 'mymodules/myname' @@ -844,9 +867,8 @@ class TestSubmodule(TestBase): sm.repo.index.commit("added new file") # change designated submodule checkout branch to the new upstream feature branch - smcw = sm.config_writer() - smcw.set_value('branch', sm_fb.name) - smcw.release() + with sm.config_writer() as smcw: + smcw.set_value('branch', sm_fb.name) assert sm.repo.is_dirty(index=True, working_tree=False) sm.repo.index.commit("changed submodule branch to '%s'" % sm_fb) @@ -870,9 +892,8 @@ class TestSubmodule(TestBase): sm_source_repo.index.commit("new file added, to past of '%r'" % sm_fb) # Change designated submodule checkout branch to a new commit in its own past - smcw = sm.config_writer() - smcw.set_value('branch', sm_pfb.path) - smcw.release() + with sm.config_writer() as smcw: + smcw.set_value('branch', sm_pfb.path) sm.repo.index.commit("changed submodule branch to '%s'" % sm_pfb) # Test submodule updates - must fail if submodule is dirty diff --git a/git/test/test_tree.py b/git/test/test_tree.py index f9282411..bb62d9bf 100644 --- a/git/test/test_tree.py +++ b/git/test/test_tree.py @@ -4,18 +4,26 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php +from io import BytesIO import os -from git.test.lib import TestBase +import sys +from unittest.case import skipIf + from git import ( Tree, Blob ) - -from io import BytesIO +from git.test.lib.helper import HIDE_WINDOWS_KNOWN_ERRORS +from git.test.lib import TestBase class TestTree(TestBase): + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and sys.version_info[:2] == (3, 5), """ + File "C:\projects\gitpython\git\cmd.py", line 559, in execute + raise GitCommandNotFound(command, err) + git.exc.GitCommandNotFound: Cmd('git') not found due to: OSError('[WinError 6] The handle is invalid') + cmdline: git cat-file --batch-check""") def test_serializable(self): # tree at the given commit contains a submodule as well roottree = self.rorepo.tree('6c1faef799095f3990e9970bc2cb10aa0221cf9c') @@ -44,6 +52,11 @@ class TestTree(TestBase): testtree._deserialize(stream) # END for each item in tree + @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and sys.version_info[:2] == (3, 5), """ + File "C:\projects\gitpython\git\cmd.py", line 559, in execute + raise GitCommandNotFound(command, err) + git.exc.GitCommandNotFound: Cmd('git') not found due to: OSError('[WinError 6] The handle is invalid') + cmdline: git cat-file --batch-check""") def test_traverse(self): root = self.rorepo.tree('0.1.6') num_recursive = 0 diff --git a/git/test/test_util.py b/git/test/test_util.py index 36fb5be3..e07417b4 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -27,18 +27,22 @@ from git.cmd import dashify from git.compat import string_types, is_win import time +import ddt class TestIterableMember(object): """A member of an iterable list""" - __slots__ = ("name", "prefix_name") + __slots__ = "name" def __init__(self, name): self.name = name - self.prefix_name = name + def __repr__(self): + return "TestIterableMember(%r)" % self.name + +@ddt.ddt class TestUtils(TestBase): def setup(self): @@ -97,20 +101,21 @@ class TestUtils(TestBase): self.assertLess(elapsed, wait_time + extra_time) def test_user_id(self): - assert '@' in get_user_id() + self.assertIn('@', get_user_id()) def test_parse_date(self): # test all supported formats def assert_rval(rval, veri_time, offset=0): - assert len(rval) == 2 - assert isinstance(rval[0], int) and isinstance(rval[1], int) - assert rval[0] == veri_time - assert rval[1] == offset + self.assertEqual(len(rval), 2) + self.assertIsInstance(rval[0], int) + self.assertIsInstance(rval[1], int) + self.assertEqual(rval[0], veri_time) + self.assertEqual(rval[1], offset) # now that we are here, test our conversion functions as well utctz = altz_to_utctz_str(offset) - assert isinstance(utctz, string_types) - assert utctz_to_altz(verify_utctz(utctz)) == offset + self.assertIsInstance(utctz, string_types) + self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset) # END assert rval utility rfc = ("Thu, 07 Apr 2005 22:13:11 +0000", 0) @@ -131,53 +136,56 @@ class TestUtils(TestBase): def test_actor(self): for cr in (None, self.rorepo.config_reader()): - assert isinstance(Actor.committer(cr), Actor) - assert isinstance(Actor.author(cr), Actor) + self.assertIsInstance(Actor.committer(cr), Actor) + self.assertIsInstance(Actor.author(cr), Actor) # END assure config reader is handled - def test_iterable_list(self): - for args in (('name',), ('name', 'prefix_')): - l = IterableList('name') - - m1 = TestIterableMember('one') - m2 = TestIterableMember('two') - - l.extend((m1, m2)) - - assert len(l) == 2 - - # contains works with name and identity - assert m1.name in l - assert m2.name in l - assert m2 in l - assert m2 in l - assert 'invalid' not in l - - # with string index - assert l[m1.name] is m1 - assert l[m2.name] is m2 - - # with int index - assert l[0] is m1 - assert l[1] is m2 - - # with getattr - assert l.one is m1 - assert l.two is m2 - - # test exceptions - self.failUnlessRaises(AttributeError, getattr, l, 'something') - self.failUnlessRaises(IndexError, l.__getitem__, 'something') - - # delete by name and index - self.failUnlessRaises(IndexError, l.__delitem__, 'something') - del(l[m2.name]) - assert len(l) == 1 - assert m2.name not in l and m1.name in l - del(l[0]) - assert m1.name not in l - assert len(l) == 0 - - self.failUnlessRaises(IndexError, l.__delitem__, 0) - self.failUnlessRaises(IndexError, l.__delitem__, 'something') - # END for each possible mode + @ddt.data(('name', ''), ('name', 'prefix_')) + def test_iterable_list(self, case): + name, prefix = case + l = IterableList(name, prefix) + + name1 = "one" + name2 = "two" + m1 = TestIterableMember(prefix + name1) + m2 = TestIterableMember(prefix + name2) + + l.extend((m1, m2)) + + self.assertEqual(len(l), 2) + + # contains works with name and identity + self.assertIn(name1, l) + self.assertIn(name2, l) + self.assertIn(m2, l) + self.assertIn(m2, l) + self.assertNotIn('invalid', l) + + # with string index + self.assertIs(l[name1], m1) + self.assertIs(l[name2], m2) + + # with int index + self.assertIs(l[0], m1) + self.assertIs(l[1], m2) + + # with getattr + self.assertIs(l.one, m1) + self.assertIs(l.two, m2) + + # test exceptions + self.failUnlessRaises(AttributeError, getattr, l, 'something') + self.failUnlessRaises(IndexError, l.__getitem__, 'something') + + # delete by name and index + self.failUnlessRaises(IndexError, l.__delitem__, 'something') + del(l[name2]) + self.assertEqual(len(l), 1) + self.assertNotIn(name2, l) + self.assertIn(name1, l) + del(l[0]) + self.assertNotIn(name1, l) + self.assertEqual(len(l), 0) + + self.failUnlessRaises(IndexError, l.__delitem__, 0) + self.failUnlessRaises(IndexError, l.__delitem__, 'something') |