Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8364597

Browse filesBrowse files
committed
test, #525: allow disabling freeze errors separately
+ cmd: use DEVNULL for non PIPEs; no open-file. + TCs: some unitestize-assertions on base & remote TCs.
1 parent 6310480 commit 8364597
Copy full SHA for 8364597

File tree

4 files changed

+64
-54
lines changed
Filter options

4 files changed

+64
-54
lines changed

‎git/cmd.py

Copy file name to clipboardExpand all lines: git/cmd.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ def execute(self, command,
539539
cmd_not_found_exception = OSError
540540
# end handle
541541

542+
stdout_sink = (PIPE
543+
if with_stdout
544+
else getattr(subprocess, 'DEVNULL', open(os.devnull, 'wb')))
542545
log.debug("Popen(%s, cwd=%s, universal_newlines=%s, shell=%s)",
543546
command, cwd, universal_newlines, shell)
544547
try:
@@ -548,9 +551,9 @@ def execute(self, command,
548551
bufsize=-1,
549552
stdin=istream,
550553
stderr=PIPE,
551-
stdout=PIPE if with_stdout else open(os.devnull, 'wb'),
554+
stdout=stdout_sink,
552555
shell=shell is not None and shell or self.USE_SHELL,
553-
close_fds=(is_posix), # unsupported on windows
556+
close_fds=is_posix, # unsupported on windows
554557
universal_newlines=universal_newlines,
555558
creationflags=PROC_CREATIONFLAGS,
556559
**subprocess_kwargs

‎git/test/test_base.py

Copy file name to clipboardExpand all lines: git/test/test_base.py
+13-12Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def tearDown(self):
4141
def test_base_object(self):
4242
# test interface of base object classes
4343
types = (Blob, Tree, Commit, TagObject)
44-
assert len(types) == len(self.type_tuples)
44+
self.assertEqual(len(types), len(self.type_tuples))
4545

4646
s = set()
4747
num_objs = 0
@@ -55,12 +55,12 @@ def test_base_object(self):
5555
item = obj_type(self.rorepo, binsha, 0, path)
5656
# END handle index objects
5757
num_objs += 1
58-
assert item.hexsha == hexsha
59-
assert item.type == typename
58+
self.assertEqual(item.hexsha, hexsha)
59+
self.assertEqual(item.type, typename)
6060
assert item.size
61-
assert item == item
62-
assert not item != item
63-
assert str(item) == item.hexsha
61+
self.assertEqual(item, item)
62+
self.assertNotEqual(not item, item)
63+
self.assertEqual(str(item), item.hexsha)
6464
assert repr(item)
6565
s.add(item)
6666

@@ -78,16 +78,16 @@ def test_base_object(self):
7878

7979
tmpfilename = tempfile.mktemp(suffix='test-stream')
8080
with open(tmpfilename, 'wb+') as tmpfile:
81-
assert item == item.stream_data(tmpfile)
81+
self.assertEqual(item, item.stream_data(tmpfile))
8282
tmpfile.seek(0)
83-
assert tmpfile.read() == data
83+
self.assertEqual(tmpfile.read(), data)
8484
os.remove(tmpfilename)
8585
# END for each object type to create
8686

8787
# each has a unique sha
88-
assert len(s) == num_objs
89-
assert len(s | s) == num_objs
90-
assert num_index_objs == 2
88+
self.assertEqual(len(s), num_objs)
89+
self.assertEqual(len(s | s), num_objs)
90+
self.assertEqual(num_index_objs, 2)
9191

9292
def test_get_object_type_by_name(self):
9393
for tname in base.Object.TYPES:
@@ -98,7 +98,7 @@ def test_get_object_type_by_name(self):
9898

9999
def test_object_resolution(self):
100100
# objects must be resolved to shas so they compare equal
101-
assert self.rorepo.head.reference.object == self.rorepo.active_branch.object
101+
self.assertEqual(self.rorepo.head.reference.object, self.rorepo.active_branch.object)
102102

103103
@with_rw_repo('HEAD', bare=True)
104104
def test_with_bare_rw_repo(self, bare_rw_repo):
@@ -110,6 +110,7 @@ def test_with_rw_repo(self, rw_repo):
110110
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
111111
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
112112

113+
#@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes! sometimes...")
113114
@with_rw_and_rw_remote_repo('0.1.6')
114115
def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
115116
assert not rw_repo.config_reader("repository").getboolean("core", "bare")

‎git/test/test_remote.py

Copy file name to clipboardExpand all lines: git/test/test_remote.py
+45-40Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.test.lib import (
8-
TestBase,
9-
with_rw_repo,
10-
with_rw_and_rw_remote_repo,
11-
fixture,
12-
GIT_DAEMON_PORT,
13-
assert_raises
14-
)
7+
import random
8+
import tempfile
9+
from unittest.case import skipIf
10+
1511
from git import (
1612
RemoteProgress,
1713
FetchInfo,
@@ -25,14 +21,19 @@
2521
Remote,
2622
GitCommandError
2723
)
28-
from git.util import IterableList, rmtree
24+
from git.cmd import Git
2925
from git.compat import string_types
30-
import tempfile
26+
from git.test.lib import (
27+
TestBase,
28+
with_rw_repo,
29+
with_rw_and_rw_remote_repo,
30+
fixture,
31+
GIT_DAEMON_PORT,
32+
assert_raises
33+
)
34+
from git.util import IterableList, rmtree, HIDE_WINDOWS_FREEZE_ERRORS, HIDE_WINDOWS_KNOWN_ERRORS
3135
import os.path as osp
32-
import random
33-
from unittest.case import skipIf
34-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
35-
from git.cmd import Git
36+
3637

3738
# assure we have repeatable results
3839
random.seed(0)
@@ -213,7 +214,7 @@ def get_info(res, remote, name):
213214
new_remote_branch.rename("other_branch_name")
214215
res = fetch_and_test(remote)
215216
other_branch_info = get_info(res, remote, new_remote_branch)
216-
assert other_branch_info.ref.commit == new_branch_info.ref.commit
217+
self.assertEqual(other_branch_info.ref.commit, new_branch_info.ref.commit)
217218

218219
# remove new branch
219220
Head.delete(new_remote_branch.repo, new_remote_branch)
@@ -223,34 +224,37 @@ def get_info(res, remote, name):
223224

224225
# prune stale tracking branches
225226
stale_refs = remote.stale_refs
226-
assert len(stale_refs) == 2 and isinstance(stale_refs[0], RemoteReference)
227+
self.assertEqual(len(stale_refs), 2)
228+
self.assertIsInstance(stale_refs[0], RemoteReference)
227229
RemoteReference.delete(rw_repo, *stale_refs)
228230

229231
# test single branch fetch with refspec including target remote
230232
res = fetch_and_test(remote, refspec="master:refs/remotes/%s/master" % remote)
231-
assert len(res) == 1 and get_info(res, remote, 'master')
233+
self.assertEqual(len(res), 1)
234+
self.assertTrue(get_info(res, remote, 'master'))
232235

233236
# ... with respec and no target
234237
res = fetch_and_test(remote, refspec='master')
235-
assert len(res) == 1
238+
self.assertEqual(len(res), 1)
236239

237240
# ... multiple refspecs ... works, but git command returns with error if one ref is wrong without
238241
# doing anything. This is new in later binaries
239242
# res = fetch_and_test(remote, refspec=['master', 'fred'])
240-
# assert len(res) == 1
243+
# self.assertEqual(len(res), 1)
241244

242245
# add new tag reference
243246
rtag = TagReference.create(remote_repo, "1.0-RV_hello.there")
244247
res = fetch_and_test(remote, tags=True)
245248
tinfo = res[str(rtag)]
246-
assert isinstance(tinfo.ref, TagReference) and tinfo.ref.commit == rtag.commit
249+
self.assertIsInstance(tinfo.ref, TagReference)
250+
self.assertEqual(tinfo.ref.commit, rtag.commit)
247251
assert tinfo.flags & tinfo.NEW_TAG
248252

249253
# adjust tag commit
250254
Reference.set_object(rtag, rhead.commit.parents[0].parents[0])
251255
res = fetch_and_test(remote, tags=True)
252256
tinfo = res[str(rtag)]
253-
assert tinfo.commit == rtag.commit
257+
self.assertEqual(tinfo.commit, rtag.commit)
254258
assert tinfo.flags & tinfo.TAG_UPDATE
255259

256260
# delete remote tag - local one will stay
@@ -326,7 +330,7 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
326330

327331
# force rejected pull
328332
res = remote.push('+%s' % lhead.reference)
329-
assert res[0].flags & PushInfo.ERROR == 0
333+
self.assertEqual(res[0].flags & PushInfo.ERROR, 0)
330334
assert res[0].flags & PushInfo.FORCED_UPDATE
331335
self._do_test_push_result(res, remote)
332336

@@ -352,7 +356,8 @@ def _assert_push_and_pull(self, remote, rw_repo, remote_repo):
352356

353357
# push force this tag
354358
res = remote.push("+%s" % new_tag.path)
355-
assert res[-1].flags & PushInfo.ERROR == 0 and res[-1].flags & PushInfo.FORCED_UPDATE
359+
self.assertEqual(res[-1].flags & PushInfo.ERROR, 0)
360+
self.assertTrue(res[-1].flags & PushInfo.FORCED_UPDATE)
356361

357362
# delete tag - have to do it using refspec
358363
res = remote.push(":%s" % new_tag.path)
@@ -485,7 +490,7 @@ def test_creation_and_removal(self, bare_rw_repo):
485490
new_name = "test_new_one"
486491
arg_list = (new_name, "git@server:hello.git")
487492
remote = Remote.create(bare_rw_repo, *arg_list)
488-
assert remote.name == "test_new_one"
493+
self.assertEqual(remote.name, "test_new_one")
489494
assert remote in bare_rw_repo.remotes
490495
assert remote.exists()
491496

@@ -520,7 +525,7 @@ def test_fetch_info(self):
520525
remote_info_line_fmt % "local/master",
521526
fetch_info_line_fmt % 'remote-tracking branch')
522527
assert not fi.ref.is_valid()
523-
assert fi.ref.name == "local/master"
528+
self.assertEqual(fi.ref.name, "local/master")
524529

525530
# handles non-default refspecs: One can specify a different path in refs/remotes
526531
# or a special path just in refs/something for instance
@@ -547,23 +552,23 @@ def test_fetch_info(self):
547552
fetch_info_line_fmt % 'tag')
548553

549554
assert isinstance(fi.ref, TagReference)
550-
assert fi.ref.path == tag_path
555+
self.assertEqual(fi.ref.path, tag_path)
551556

552557
# branches default to refs/remotes
553558
fi = FetchInfo._from_line(self.rorepo,
554559
remote_info_line_fmt % "remotename/branch",
555560
fetch_info_line_fmt % 'branch')
556561

557562
assert isinstance(fi.ref, RemoteReference)
558-
assert fi.ref.remote_name == 'remotename'
563+
self.assertEqual(fi.ref.remote_name, 'remotename')
559564

560565
# but you can force it anywhere, in which case we only have a references
561566
fi = FetchInfo._from_line(self.rorepo,
562567
remote_info_line_fmt % "refs/something/branch",
563568
fetch_info_line_fmt % 'branch')
564569

565570
assert type(fi.ref) is Reference
566-
assert fi.ref.path == "refs/something/branch"
571+
self.assertEqual(fi.ref.path, "refs/something/branch")
567572

568573
def test_uncommon_branch_names(self):
569574
stderr_lines = fixture('uncommon_branch_prefix_stderr').decode('ascii').splitlines()
@@ -574,8 +579,8 @@ def test_uncommon_branch_names(self):
574579
res = [FetchInfo._from_line('ShouldntMatterRepo', stderr, fetch_line)
575580
for stderr, fetch_line in zip(stderr_lines, fetch_lines)]
576581
assert len(res)
577-
assert res[0].remote_ref_path == 'refs/pull/1/head'
578-
assert res[0].ref.path == 'refs/heads/pull/1/head'
582+
self.assertEqual(res[0].remote_ref_path, 'refs/pull/1/head')
583+
self.assertEqual(res[0].ref.path, 'refs/heads/pull/1/head')
579584
assert isinstance(res[0].ref, Head)
580585

581586
@with_rw_repo('HEAD', bare=False)
@@ -588,36 +593,36 @@ def test_multiple_urls(self, rw_repo):
588593
remote = rw_repo.remotes[0]
589594
# Testing setting a single URL
590595
remote.set_url(test1)
591-
assert list(remote.urls) == [test1]
596+
self.assertEqual(list(remote.urls), [test1])
592597

593598
# Testing replacing that single URL
594599
remote.set_url(test1)
595-
assert list(remote.urls) == [test1]
600+
self.assertEqual(list(remote.urls), [test1])
596601
# Testing adding new URLs
597602
remote.set_url(test2, add=True)
598-
assert list(remote.urls) == [test1, test2]
603+
self.assertEqual(list(remote.urls), [test1, test2])
599604
remote.set_url(test3, add=True)
600-
assert list(remote.urls) == [test1, test2, test3]
605+
self.assertEqual(list(remote.urls), [test1, test2, test3])
601606
# Testing removing an URL
602607
remote.set_url(test2, delete=True)
603-
assert list(remote.urls) == [test1, test3]
608+
self.assertEqual(list(remote.urls), [test1, test3])
604609
# Testing changing an URL
605610
remote.set_url(test3, test2)
606-
assert list(remote.urls) == [test1, test2]
611+
self.assertEqual(list(remote.urls), [test1, test2])
607612

608613
# will raise: fatal: --add --delete doesn't make sense
609614
assert_raises(GitCommandError, remote.set_url, test2, add=True, delete=True)
610615

611616
# Testing on another remote, with the add/delete URL
612617
remote = rw_repo.create_remote('another', url=test1)
613618
remote.add_url(test2)
614-
assert list(remote.urls) == [test1, test2]
619+
self.assertEqual(list(remote.urls), [test1, test2])
615620
remote.add_url(test3)
616-
assert list(remote.urls) == [test1, test2, test3]
621+
self.assertEqual(list(remote.urls), [test1, test2, test3])
617622
# Testing removing all the URLs
618623
remote.delete_url(test2)
619-
assert list(remote.urls) == [test1, test3]
624+
self.assertEqual(list(remote.urls), [test1, test3])
620625
remote.delete_url(test1)
621-
assert list(remote.urls) == [test3]
626+
self.assertEqual(list(remote.urls), [test3])
622627
# will raise fatal: Will not delete all non-push URLs
623628
assert_raises(GitCommandError, remote.delete_url, test3)

‎git/util.py

Copy file name to clipboardExpand all lines: git/util.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#: so the errors marked with this var are considered "acknowledged" ones, awaiting remedy,
5252
#: till then, we wish to hide them.
5353
HIDE_WINDOWS_KNOWN_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_KNOWN_ERRORS', True)
54+
HIDE_WINDOWS_FREEZE_ERRORS = is_win and os.environ.get('HIDE_WINDOWS_FREEZE_ERRORS', HIDE_WINDOWS_KNOWN_ERRORS)
5455

5556
#{ Utility Methods
5657

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.