Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
thelabnyc
python-versiontag
Commits
de6e0062
Commit
de6e0062
authored
Jan 23, 2017
by
Craig Weber
Browse files
Add Python 2.7 Support
parent
0ee7dc38
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
3 deletions
+109
-3
.travis.yml
.travis.yml
+3
-1
setup.py
setup.py
+4
-0
versiontag/tests/__init__.py
versiontag/tests/__init__.py
+0
-0
versiontag/tests/test_versiontag.py
versiontag/tests/test_versiontag.py
+14
-2
versiontag/tests/utils.py
versiontag/tests/utils.py
+88
-0
No files found.
.travis.yml
View file @
de6e0062
language
:
python
python
:
-
"
2.7"
-
"
3.3"
-
"
3.4"
-
"
3.5"
-
"
3.5-dev"
-
"
3.6"
-
"
3.6-dev"
addons
:
apt
:
...
...
setup.py
View file @
de6e0062
...
...
@@ -28,9 +28,13 @@ setup(
'Operating System :: Unix'
,
'Operating System :: MacOS :: MacOS X'
,
'Programming Language :: Python'
,
'Programming Language :: Python :: 2'
,
'Programming Language :: Python :: 2.7'
,
'Programming Language :: Python :: 3'
,
'Programming Language :: Python :: 3.3'
,
'Programming Language :: Python :: 3.4'
,
'Programming Language :: Python :: 3.5'
,
'Programming Language :: Python :: 3.6'
,
],
author
=
'Craig Weber'
,
author_email
=
'crgwbr@gmail.com'
,
...
...
tests/__init__.py
→
versiontag/
tests/__init__.py
View file @
de6e0062
File moved
tests/test_versiontag.py
→
versiontag/
tests/test_versiontag.py
View file @
de6e0062
import
subprocess
import
tempfile
import
unittest
import
os
import
logging
try
:
from
tempfile
import
TemporaryDirectory
except
ImportError
:
from
.utils
import
TemporaryDirectory
import
versiontag
...
...
@@ -15,22 +19,26 @@ def silent_call(*args):
class
VersionTagTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
logging
.
disable
(
logging
.
CRITICAL
)
self
.
repo_dir
=
tempfile
.
TemporaryDirectory
()
self
.
repo_dir
=
TemporaryDirectory
()
os
.
chdir
(
self
.
repo_dir
.
name
)
def
tearDown
(
self
):
self
.
repo_dir
.
cleanup
()
logging
.
disable
(
logging
.
NOTSET
)
def
_set_author
(
self
):
silent_call
(
'git'
,
'config'
,
'user.email'
,
'travis@example.com'
)
silent_call
(
'git'
,
'config'
,
'user.name'
,
'Travis von Builder'
)
def
test_no_repo
(
self
):
"""No repo returns default version"""
self
.
assertEqual
(
versiontag
.
get_version
(),
'r0.0.0'
)
self
.
assertEqual
(
versiontag
.
get_version
(
pypi
=
True
),
'0.0.0'
)
def
test_no_commits
(
self
):
"""No tags returns default version"""
silent_call
(
'git'
,
'init'
)
...
...
@@ -38,6 +46,7 @@ class VersionTagTest(unittest.TestCase):
self
.
assertEqual
(
versiontag
.
get_version
(),
'r0.0.0'
)
self
.
assertEqual
(
versiontag
.
get_version
(
pypi
=
True
),
'0.0.0'
)
def
test_head_is_tagged
(
self
):
"""Should return most recent tag"""
silent_call
(
'git'
,
'init'
)
...
...
@@ -47,6 +56,7 @@ class VersionTagTest(unittest.TestCase):
self
.
assertEqual
(
versiontag
.
get_version
(),
'r1.2.3'
)
self
.
assertEqual
(
versiontag
.
get_version
(
pypi
=
True
),
'1.2.3'
)
def
test_head_is_post_release
(
self
):
"""Subsequent commits show as post releases"""
silent_call
(
'git'
,
'init'
)
...
...
@@ -65,6 +75,7 @@ class VersionTagTest(unittest.TestCase):
self
.
assertTrue
(
versiontag
.
get_version
().
startswith
(
'r1.2.4'
)
)
self
.
assertEqual
(
versiontag
.
get_version
(
pypi
=
True
),
'1.2.4'
)
def
test_caching_with_removed_git_folder
(
self
):
"""Caching continues to return release even if git repository disappears"""
silent_call
(
'git'
,
'init'
)
...
...
@@ -88,6 +99,7 @@ class VersionTagTest(unittest.TestCase):
self
.
assertEqual
(
versiontag
.
get_version
(),
'r0.0.0'
)
self
.
assertEqual
(
versiontag
.
get_version
(
pypi
=
True
),
'0.0.0'
)
def
test_pypi_normalize
(
self
):
# Final releases
self
.
assertEqual
(
versiontag
.
convert_to_pypi_version
(
'r1.2.3'
),
'1.2.3'
)
...
...
versiontag/tests/utils.py
0 → 100644
View file @
de6e0062
from
__future__
import
print_function
import
warnings
as
_warnings
import
os
as
_os
from
tempfile
import
mkdtemp
class
TemporaryDirectory
(
object
):
"""
Create and return a temporary directory. This has the same behavior
as mkdtemp but can be used as a context manager. For example:
with TemporaryDirectory() as tmpdir:
...
Upon exiting the context, the directory and everything contained
in it are removed.
"""
def
__init__
(
self
,
suffix
=
""
,
prefix
=
"tmp"
,
dir
=
None
):
self
.
_closed
=
False
self
.
name
=
None
# Handle mkdtemp raising an exception
self
.
name
=
mkdtemp
(
suffix
,
prefix
,
dir
)
def
__repr__
(
self
):
return
"<{} {!r}>"
.
format
(
self
.
__class__
.
__name__
,
self
.
name
)
def
__enter__
(
self
):
return
self
.
name
def
cleanup
(
self
,
_warn
=
False
):
if
self
.
name
and
not
self
.
_closed
:
try
:
self
.
_rmtree
(
self
.
name
)
except
(
TypeError
,
AttributeError
)
as
ex
:
# Issue #10188: Emit a warning on stderr
# if the directory could not be cleaned
# up due to missing globals
if
"None"
not
in
str
(
ex
):
raise
print
(
"ERROR: {!r} while cleaning up {!r}"
.
format
(
ex
,
self
,),
file
=
_sys
.
stderr
)
return
self
.
_closed
=
True
if
_warn
:
self
.
_warn
(
"Implicitly cleaning up {!r}"
.
format
(
self
),
ResourceWarning
)
def
__exit__
(
self
,
exc
,
value
,
tb
):
self
.
cleanup
()
def
__del__
(
self
):
# Issue a ResourceWarning if implicit cleanup needed
self
.
cleanup
(
_warn
=
True
)
# XXX (ncoghlan): The following code attempts to make
# this class tolerant of the module nulling out process
# that happens during CPython interpreter shutdown
# Alas, it doesn't actually manage it. See issue #10188
_listdir
=
staticmethod
(
_os
.
listdir
)
_path_join
=
staticmethod
(
_os
.
path
.
join
)
_isdir
=
staticmethod
(
_os
.
path
.
isdir
)
_islink
=
staticmethod
(
_os
.
path
.
islink
)
_remove
=
staticmethod
(
_os
.
remove
)
_rmdir
=
staticmethod
(
_os
.
rmdir
)
_warn
=
_warnings
.
warn
def
_rmtree
(
self
,
path
):
# Essentially a stripped down version of shutil.rmtree. We can't
# use globals because they may be None'ed out at shutdown.
for
name
in
self
.
_listdir
(
path
):
fullname
=
self
.
_path_join
(
path
,
name
)
try
:
isdir
=
self
.
_isdir
(
fullname
)
and
not
self
.
_islink
(
fullname
)
except
OSError
:
isdir
=
False
if
isdir
:
self
.
_rmtree
(
fullname
)
else
:
try
:
self
.
_remove
(
fullname
)
except
OSError
:
pass
try
:
self
.
_rmdir
(
path
)
except
OSError
:
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment