Repository: Duke-GCB/DukeDSClient

Issue:
Check for lowercase utf-8 in encoding
Testing Windows 7 with Anaconda(python 3.6) 4.3.0 ignores the PYTHONIOENCODING value and displays lowercase utf-8. 
Change the code in ddsc/core/util.py verify_terminal_encoding to ignore case.

Discussion:

Patch:
diff --git a/ddsc/cmdparser.py b/ddsc/cmdparser.py
index 91f6940..fdceb62 100644
--- a/ddsc/cmdparser.py
+++ b/ddsc/cmdparser.py
@@ -3,6 +3,7 @@ Command line parser for the application.
 """
 import os
 import argparse
+import six
 from builtins import str
 
 
@@ -26,7 +27,7 @@ def to_unicode(s):
     :param s: string to convert to unicode
     :return: unicode string for argument
     """
-    return str(s)
+    return s if six.PY3 else str(s, 'utf-8')
 
 
 def add_project_name_arg(arg_parser, required=True, help_text="Name of the remote project to manage."):
diff --git a/ddsc/core/util.py b/ddsc/core/util.py
index a5e7112..10e0445 100644
--- a/ddsc/core/util.py
+++ b/ddsc/core/util.py
@@ -232,9 +232,9 @@ def wait_for_processes(processes, size, progress_queue, watcher, item):
 
 def verify_terminal_encoding(encoding):
     """
-    Raises ValueError with error message when terminal encoding is not Unicode(contains UTF).
+    Raises ValueError with error message when terminal encoding is not Unicode(contains UTF ignoring case).
     :param encoding: str: encoding we want to check
     """
     encoding = encoding or ''
-    if not ("UTF" in encoding):
+    if not ("UTF" in encoding.upper()):
         raise ValueError(TERMINAL_ENCODING_NOT_UTF_ERROR)


Test patch:
diff --git a/ddsc/core/tests/test_util.py b/ddsc/core/tests/test_util.py
new file mode 100644
index 0000000..daf00cd
--- /dev/null
+++ b/ddsc/core/tests/test_util.py
@@ -0,0 +1,24 @@
+from unittest import TestCase
+
+from ddsc.core.util import verify_terminal_encoding
+
+
+class TestUtil(TestCase):
+
+    def test_verify_terminal_encoding_upper(self):
+        verify_terminal_encoding('UTF')
+
+    def test_verify_terminal_encoding_lower(self):
+        verify_terminal_encoding('utf')
+
+    def test_verify_terminal_encoding_ascii_raises(self):
+        with self.assertRaises(ValueError):
+            verify_terminal_encoding('ascii')
+
+    def test_verify_terminal_encoding_empty_raises(self):
+        with self.assertRaises(ValueError):
+            verify_terminal_encoding('')
+
+    def test_verify_terminal_encoding_none_raises(self):
+        with self.assertRaises(ValueError):
+            verify_terminal_encoding(None)