Skip to content

Test project on Windows with MINGW git (conda2.7&3.4/cpy-3.5) #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Oct 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7842e92
test, deps: FIX `mock` deps on py3.
ankostis Sep 14, 2016
1210ec7
apveyor: Wintest project with MINGW/Cygwin git (conda2.7&3.4/cpy-3.5)
ankostis Sep 25, 2016
51bf7cb
win: GC.collect on all TC.tearDown to fix appveyor hang runs
ankostis Sep 25, 2016
082851e
apveyor: simplify test.
ankostis Sep 25, 2016
7ec2f8a
apveyor, #519: FIX incomplete Popen pump
ankostis Sep 25, 2016
fa70623
test, #519: FIX appveyor conda & failures in py2.6 `assertRaisesRegexp`
ankostis Sep 26, 2016
7bbaac2
test, #519: Popen() universal_newlin.es NoWindow in Winfoes
ankostis Sep 26, 2016
b343718
test, #519: Popen() pump: remove WaitGroup
ankostis Sep 26, 2016
783ad99
test, #519: Travis-test flake8/site on py3.4 only
ankostis Sep 26, 2016
45f8f20
Win, #519: FIX WinHangs: Popen() CREATE_NEW_PROCESS_GROUP to allow kill
ankostis Sep 26, 2016
29eb301
win, #519: proc.terminate() instead of kill(SIGTERM)
ankostis Sep 26, 2016
f495e94
src, #519: collect all is_<platform>() calls
ankostis Sep 26, 2016
aa3f2fa
src, #519: Improve daemon launch so Win does not stuck
ankostis Sep 26, 2016
618e625
test, #519: Try appveyor advice for never-ending builds
ankostis Sep 26, 2016
6a3c95b
test, #519: No remote TCs, git-daemon cannot die@!
ankostis Sep 26, 2016
c572a8d
Win, #519: FIX undead Git-daemon on Windows
ankostis Sep 26, 2016
278423f
Travis, #519: split flake8 from sphinx, to speedup tests
ankostis Sep 27, 2016
1124e19
Appveyor, #519: Git-daemon also for Cygwin-git
ankostis Sep 27, 2016
25a2ebf
Win, #519: Remove `git.cmd` failback - no longer exists.
ankostis Sep 27, 2016
df2fb54
PY2, #519: FIX GitCommandError.tostr() encoding issue
ankostis Sep 27, 2016
e61439b
src: constify is_<platform>() calls
ankostis Sep 27, 2016
4cede23
Win, #519: Ensure fixtures & bashscript checked-out eol=lf
ankostis Sep 27, 2016
434505f
TCs: unittestize many test-docs assertions
ankostis Sep 27, 2016
137ee6e
Win, #519: FIX with_rw_directory() to remove read-only dirs
ankostis Sep 27, 2016
57550cc
appveyor: Try to fix conda-3.4 & READM line-wdith
ankostis Sep 27, 2016
4674163
test: Start using `ddt` library for TCs
ankostis Sep 27, 2016
a5db3d3
io, dif: #519: FIX DIFF freeze when reading from GIL
ankostis Sep 27, 2016
cf2335a
Win, hook, #519: Consume Hook Popen-proc out of GIL
ankostis Sep 27, 2016
f11fdf1
remote, #519: FIX1-of-2 double-decoding push-infos
ankostis Sep 28, 2016
44c6d0b
Proc, #519: Rework error-exc msgs & log thread-pumps errors
ankostis Sep 28, 2016
6e98416
remote, #519: INCOMPLETE FIX-2 double-decoding push-infos
ankostis Sep 28, 2016
0574b8b
ABANDON select/poll
ankostis Sep 28, 2016
f1d2d06
FIX tox/requirements
ankostis Sep 28, 2016
3959556
FIX hook TC on PY3+Win & indeterministic lock timing.
ankostis Sep 28, 2016
842fb68
Appveyor, #519: disable Cygiwin harness.
ankostis Sep 29, 2016
b114f3b
ci: Capture logging for Popen() execute statements.
ankostis Sep 29, 2016
d84b960
cfg_TCs, #519: FIX config resource leaks
ankostis Oct 1, 2016
13d399f
ci: restore ci log-level to normal, coverage on Win-Appveyor
ankostis Oct 1, 2016
a79cf67
repo-TCs, #519: FIX config resource leaks
ankostis Oct 1, 2016
b8b025f
Win, #519: FIX repo TCs.
ankostis Oct 1, 2016
bdf1e68
Merge remote-tracking branch 'origin/master' into appveyor
ankostis Oct 1, 2016
9a52168
io, #519: ALL open() --> with open()
ankostis Oct 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repo-TCs, #519: FIX config resource leaks
+ Modify lock/read-config-file code to ensure files closed.
+ Use `with GitConfigarser()` more systematically in TCs.
+ Clear any locks left hanging from prev Tcs.
+ Util: mark lock-files as SHORT_LIVED; save some SSDs...
  • Loading branch information
ankostis committed Oct 1, 2016
commit a79cf677744e2c1721fa55f934fa07034bc54b0a
18 changes: 6 additions & 12 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ def __hash__(self):
# Description property
def _get_description(self):
filename = join(self.git_dir, 'description')
return open(filename, 'rb').read().rstrip().decode(defenc)
with open(filename, 'rb') as fp:
return fp.read().rstrip().decode(defenc)

def _set_description(self, descr):
filename = join(self.git_dir, 'description')
open(filename, 'wb').write((descr + '\n').encode(defenc))
with open(filename, 'wb') as fp:
fp.write((descr + '\n').encode(defenc))

description = property(_get_description, _set_description,
doc="the project's description")
Expand Down Expand Up @@ -548,11 +550,8 @@ def _get_alternates(self):
alternates_path = join(self.git_dir, 'objects', 'info', 'alternates')

if os.path.exists(alternates_path):
try:
f = open(alternates_path, 'rb')
with open(alternates_path, 'rb') as f:
alts = f.read().decode(defenc)
finally:
f.close()
return alts.strip().splitlines()
else:
return list()
Expand All @@ -573,13 +572,8 @@ def _set_alternates(self, alts):
if isfile(alternates_path):
os.remove(alternates_path)
else:
try:
f = open(alternates_path, 'wb')
with open(alternates_path, 'wb') as f:
f.write("\n".join(alts).encode(defenc))
finally:
f.close()
# END file handling
# END alts handling

alternates = property(_get_alternates, _set_alternates,
doc="Retrieve a list of alternates paths or set a list paths to be used as alternates")
Expand Down
4 changes: 2 additions & 2 deletions git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


def touch(filename):
fp = open(filename, "ab")
fp.close()
with open(filename, "ab"):
pass
return filename


Expand Down
3 changes: 1 addition & 2 deletions git/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from git import (
GitConfigParser
)
from git.compat import (
string_types)
from git.compat import string_types
from git.config import cp
from git.test.lib import (
TestCase,
Expand Down
80 changes: 45 additions & 35 deletions git/test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import glob
from io import BytesIO
import itertools
import os
import pickle
import sys
import tempfile

from git.test.lib import (
patch,
TestBase,
with_rw_repo,
fixture,
assert_false,
assert_equal,
assert_true,
raises
)
from git import (
InvalidGitRepositoryError,
Repo,
Expand All @@ -33,23 +29,28 @@
BadName,
GitCommandError
)
from git.repo.fun import touch
from git.util import join_path_native, rmtree
from git.compat import string_types
from git.exc import (
BadObject,
)
from gitdb.util import bin_to_hex
from git.compat import string_types
from git.repo.fun import touch
from git.test.lib import (
patch,
TestBase,
with_rw_repo,
fixture,
assert_false,
assert_equal,
assert_true,
raises
)
from git.test.lib import with_rw_directory

import os
import sys
import tempfile
import itertools
from io import BytesIO

from git.util import join_path_native, rmtree, rmfile
from gitdb.util import bin_to_hex
from nose import SkipTest

import os.path as osp


def iter_flatten(lol):
for items in lol:
Expand All @@ -61,9 +62,23 @@ def flatten(lol):
return list(iter_flatten(lol))


_tc_lock_fpaths = osp.join(osp.dirname(__file__), '../../.git/*.lock')


def _rm_lock_files():
for lfp in glob.glob(_tc_lock_fpaths):
rmfile(lfp)


class TestRepo(TestBase):

def setUp(self):
_rm_lock_files()

def tearDown(self):
for lfp in glob.glob(_tc_lock_fpaths):
if osp.isfile(lfp):
raise AssertionError('Previous TC left hanging git-lock file: %s', lfp)
import gc
gc.collect()

Expand Down Expand Up @@ -309,10 +324,9 @@ def test_tag(self):

def test_archive(self):
tmpfile = tempfile.mktemp(suffix='archive-test')
stream = open(tmpfile, 'wb')
self.rorepo.archive(stream, '0.1.6', path='doc')
assert stream.tell()
stream.close()
with open(tmpfile, 'wb') as stream:
self.rorepo.archive(stream, '0.1.6', path='doc')
assert stream.tell()
os.remove(tmpfile)

@patch.object(Git, '_call_process')
Expand Down Expand Up @@ -401,9 +415,8 @@ def test_untracked_files(self, rwrepo):

num_recently_untracked = 0
for fpath in files:
fd = open(fpath, "wb")
fd.close()
# END for each filename
with open(fpath, "wb"):
pass
untracked_files = rwrepo.untracked_files
num_recently_untracked = len(untracked_files)

Expand All @@ -426,19 +439,16 @@ def test_config_reader(self):
def test_config_writer(self):
for config_level in self.rorepo.config_level:
try:
writer = self.rorepo.config_writer(config_level)
assert not writer.read_only
writer.release()
with self.rorepo.config_writer(config_level) as writer:
self.assertFalse(writer.read_only)
except IOError:
# its okay not to get a writer for some configuration files if we
# have no permissions
pass
# END for each config level

def test_config_level_paths(self):
for config_level in self.rorepo.config_level:
assert self.rorepo._get_config_path(config_level)
# end for each config level

def test_creation_deletion(self):
# just a very quick test to assure it generally works. There are
Expand All @@ -448,8 +458,8 @@ def test_creation_deletion(self):

tag = self.rorepo.create_tag("new_tag", "HEAD~2")
self.rorepo.delete_tag(tag)
writer = self.rorepo.config_writer()
writer.release()
with self.rorepo.config_writer():
pass
remote = self.rorepo.create_remote("new_remote", "git@server:repo.git")
self.rorepo.delete_remote(remote)

Expand Down
5 changes: 4 additions & 1 deletion git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ def _obtain_lock_or_raise(self):
(self._file_path, lock_file))

try:
fd = os.open(lock_file, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0)
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
if is_win:
flags |= getattr(os, 'O_SHORT_LIVED')
fd = os.open(lock_file, flags, 0)
os.close(fd)
except OSError as e:
raise IOError(str(e))
Expand Down