Skip to content

Commit

Permalink
#30340 fix unittest and possible mimetypes errors on Win Python v2.7.8
Browse files Browse the repository at this point in the history
Fixes a unittest issue where the path of some tests would be incorrectly extracted. Closes #74.
Fixes a `TypeError` that could arise on Windows using Python v2.7.7/8 if you have NULL bytes in your registry. This is due to a bug in Python (http://bugs.python.org/issue23371) which was addressed in v2.7.9. The fix catches the exception that would be raised and loads the bundled and patched mimetypes library instead. Closes #88

Thanks to @patrickwolf for the reports and info
  • Loading branch information
KP committed Sep 15, 2015
1 parent 8f5f51f commit 1109d20
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -55,7 +55,8 @@ Integration and unit tests are provided.

**v3.0.23 - TBD**

+ TBD
+ Fix for python bug on Windows loading mimetypes module (http://bugs.python.org/issue23371) thanks to @patrickwolf.
+ Fix for tests on older versions of python.

**v3.0.22 - 2015 Sept 9**

Expand Down
6 changes: 4 additions & 2 deletions shotgun_api3/sg_26.py
Expand Up @@ -29,7 +29,9 @@
import mimetypes # used for attachment upload
try:
mimetypes.add_type('video/webm','.webm') # try adding to test for unicode error
except UnicodeDecodeError:
# Ticket #25579 python bug on windows with unicode
except (UnicodeDecodeError, TypeError):
# Ticket #25579: python bug on windows with unicode
# Ticket #23371: mimetypes initialization fails on Windows because of TypeError
# (http://bugs.python.org/issue23371)
# Use patched version of mimetypes
from .lib import mimetypes as mimetypes
8 changes: 7 additions & 1 deletion tests/test_api.py
Expand Up @@ -2142,11 +2142,17 @@ def _has_unicode(data):
return False

def _get_path(url):
"""Returns path component of a url without the sheme, host, query, anchor, or any other
additional elements.
For example, the url "https://foo.shotgunstudio.com/page/2128#Shot_1190_sr10101_034"
returns "/page/2128"
"""
# url_parse returns native objects for older python versions (2.4)
if isinstance(url, dict):
return url.get('path')
elif isinstance(url, tuple):
return os.path.join(url[:4])
# 3rd component is the path
return url[2]
else:
return url.path

Expand Down
3 changes: 2 additions & 1 deletion tests/test_client.py
Expand Up @@ -382,7 +382,8 @@ def test_parse_records(self):
system = platform.system().lower()
if system =='darwin':
local_path_field = "local_path_mac"
elif system == 'windows':
# python 2.4 returns 'Microsoft'
elif system in ['windows', 'microsoft']:
local_path_field = "local_path_windows"
elif system == 'linux':
local_path_field = "local_path_linux"
Expand Down

0 comments on commit 1109d20

Please sign in to comment.