Skip to content

Commit

Permalink
Merge pull request #1 from edx/saleem-latif/python.3.support
Browse files Browse the repository at this point in the history
Added support for Python 3.5
  • Loading branch information
saleem-latif authored Jul 20, 2018
2 parents 424eeda + 1b64926 commit 92a9721
Show file tree
Hide file tree
Showing 42 changed files with 273 additions and 248 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'tincan/conversions',
'tincan/documents',
],
version='0.0.5',
version='0.0.5.py.35',
description='A Python library for implementing Tin Can API.',
author='Rustici Software',
author_email='mailto:[email protected]',
Expand Down
6 changes: 3 additions & 3 deletions test/activity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -91,12 +91,12 @@ def test_ToJSONFromJSON(self):
check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
activity = Activity.from_json(json_str)
self.activityVerificationHelper(activity)
self.assertEqual(activity.to_json(), check_str)
self.assertEqual(json.loads(activity.to_json()), json.loads(check_str))

def test_ToJSON(self):
check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
activity = Activity(**{'id': 'test', 'definition': {}, 'object_type': 'Activity'})
self.assertEqual(activity.to_json(), check_str)
self.assertEqual(json.loads(activity.to_json()), json.loads(check_str))

def test_setDefinitionException(self):
activity = Activity()
Expand Down
4 changes: 2 additions & 2 deletions test/activitydefinition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_ToJSONIgnoreNone(self):
'description': {'en-US': 'test'},
'more_info': None
})
self.assertEqual(adef.to_json(), '{"description": {"en-US": "test"}}')
self.assertEqual(json.loads(adef.to_json()), json.loads('{"description": {"en-US": "test"}}'))

def test_ToJSONEmpty(self):
adef = ActivityDefinition()
Expand Down
9 changes: 5 additions & 4 deletions test/activitylist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -93,12 +93,13 @@ def test_ToJSONFromJSON(self):
json_str = '[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]'
alist = ActivityList.from_json(json_str)
self.listVerificationHelper(alist)
self.assertEqual(alist.to_json(), json_str)
self.assertEqual(json.loads(alist.to_json()), json.loads(json_str))

def test_ToJSON(self):
alist = ActivityList([{"id": "test1"}, {"id": "test2"}])
self.assertEqual(alist.to_json(),
'[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]')
self.assertEqual(json.loads(alist.to_json()),
json.loads(
'[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]'))

def test_setItem(self):
alist = ActivityList([Activity(), Activity()])
Expand Down
17 changes: 9 additions & 8 deletions test/attachment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -301,10 +301,11 @@ def test_ToJSON(self):
attachment = Attachment(
**{"usage_type": "test", "content_type": "test", "length": 1, "sha2": "test", "fileurl": "test",
"display": {"en-US": "test"}, "description": {"en-US": "test"}})
self.assertEqual(attachment.to_json(), ('{"sha2": "test", "contentType": "test", '
'"description": {"en-US": "test"}, '
'"usageType": "test", "length": 1, "fileUrl": "test", '
'"display": {"en-US": "test"}}'))
self.assertEqual(json.loads(attachment.to_json()),
json.loads('{"sha2": "test", "contentType": "test", '
'"description": {"en-US": "test"}, '
'"usageType": "test", "length": 1, "fileUrl": "test", '
'"display": {"en-US": "test"}}'))

def test_ToJSONEmpty(self):
attachment = Attachment()
Expand All @@ -322,9 +323,9 @@ def test_ToJSONFromJSON(self):
self.languageMapVerificationHelper(attachment.description)
self.languageMapVerificationHelper(attachment.display)
self.assertEqual(
attachment.to_json(),
'{"sha2": "test", "contentType": "test", "description": {"en-US": "test"}, '
'"usageType": "test", "length": 1, "fileUrl": "test", "display": {"en-US": "test"}}')
json.loads(attachment.to_json()),
json.loads('{"sha2": "test", "contentType": "test", "description": {"en-US": "test"}, '
'"usageType": "test", "length": 1, "fileUrl": "test", "display": {"en-US": "test"}}'))

def languageMapVerificationHelper(self, value):
self.assertIsInstance(value, LanguageMap)
Expand Down
2 changes: 1 addition & 1 deletion test/documents/activity_profile_document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_activity_setter(self):
doc = ActivityProfileDocument()
doc.activity = {"id": "http://tincanapi.com/TinCanPython/Test/Unit/0"}

self.assertEquals(doc.activity.id, "http://tincanapi.com/TinCanPython/Test/Unit/0")
self.assertEqual(doc.activity.id, "http://tincanapi.com/TinCanPython/Test/Unit/0")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion test/documents/state_document_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_activity_setter(self):
doc = StateDocument()
doc.activity = {"id": "http://tincanapi.com/TinCanPython/Test/Unit/0"}

self.assertEquals(doc.activity.id, "http://tincanapi.com/TinCanPython/Test/Unit/0")
self.assertEqual(doc.activity.id, "http://tincanapi.com/TinCanPython/Test/Unit/0")


if __name__ == "__main__":
Expand Down
20 changes: 10 additions & 10 deletions test/group_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
from main import setup_tincan_path

setup_tincan_path()
from tincan import Group, Agent, AgentAccount
from tincan import Group, Agent


class GroupTest(unittest.TestCase):
def test_InitEmpty(self):
group = Group()
self.assertEquals(group.member, [])
self.assertEqual(group.member, [])

def test_InitObjectType(self):
group = Group(object_type='Group')
Expand All @@ -45,7 +45,7 @@ def test_FromJSONExceptionEmpty(self):

def test_FromJSONEmptyObject(self):
group = Group.from_json('{}')
self.assertEquals(group.member, [])
self.assertEqual(group.member, [])

def test_FromJSONmember(self):
group = Group.from_json('''{"member":[{"name":"test"}]}''')
Expand Down Expand Up @@ -74,15 +74,15 @@ def test_InitUnpack(self):
def test_ToJSONFromJSON(self):
group = Group.from_json('{"member":[{"name":"test"}, {"name":"test2"}]}')
self.assertIsInstance(group.member[0], Agent)
self.assertEqual(group.to_json(),
'{"member": [{"name": "test", "objectType": "Agent"}, '
'{"name": "test2", "objectType": "Agent"}], "objectType": "Group"}')
self.assertEqual(json.loads(group.to_json()),
json.loads('{"member": [{"name": "test", "objectType": "Agent"}, '
'{"name": "test2", "objectType": "Agent"}], "objectType": "Group"}'))

def test_ToJSON(self):
group = Group(**{'member': [{'name': 'test'}, {'name': 'test2'}]})
self.assertEqual(group.to_json(),
'{"member": [{"name": "test", "objectType": "Agent"}, '
'{"name": "test2", "objectType": "Agent"}], "objectType": "Group"}')
self.assertEqual(json.loads(group.to_json()),
json.loads('{"member": [{"name": "test", "objectType": "Agent"}, '
'{"name": "test2", "objectType": "Agent"}], "objectType": "Group"}'))


if __name__ == '__main__':
Expand Down
6 changes: 3 additions & 3 deletions test/interactioncomponent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -138,11 +138,11 @@ def test_ToJSONFromJSON(self):
icomp = InteractionComponent.from_json(json_str)
self.assertEqual(icomp.id, 'test')
self.descriptionVerificationHelper(icomp.description)
self.assertEqual(icomp.to_json(), json_str)
self.assertEqual(json.loads(icomp.to_json()), json.loads(json_str))

def test_ToJSON(self):
icomp = InteractionComponent(**{"id": "test", "description": {"en-US": "test"}})
self.assertEqual(icomp.to_json(), '{"id": "test", "description": {"en-US": "test"}}')
self.assertEqual(json.loads(icomp.to_json()), json.loads('{"id": "test", "description": {"en-US": "test"}}'))

def test_ToJSONIgnoreNoneDescription(self):
icomp = InteractionComponent(id='test')
Expand Down
10 changes: 5 additions & 5 deletions test/interactioncomponentlist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -95,15 +95,15 @@ def test_ToJSONFromJSON(self):
'{"id": "test2", "description": {"en-US": "test2"}}]'
iclist = InteractionComponentList.from_json(json_str)
self.listVerificationHelper(iclist)
self.assertEqual(iclist.to_json(), json_str)
self.assertEqual(json.loads(iclist.to_json()), json.loads(json_str))

def test_ToJSON(self):
iclist = InteractionComponentList(
[{"id": "test1", "description": {"en-US": "test1"}}, {"id": "test2", "description": {"en-US": "test2"}}])
# since the map is unordered, it is ok that to_json() changes ordering
self.assertEqual(iclist.to_json(),
'[{"id": "test1", "description": {"en-US": "test1"}}, '
'{"id": "test2", "description": {"en-US": "test2"}}]')
self.assertEqual(json.loads(iclist.to_json()),
json.loads('[{"id": "test1", "description": {"en-US": "test1"}}, '
'{"id": "test2", "description": {"en-US": "test2"}}]'))

def test_setItem(self):
iclist = InteractionComponentList([InteractionComponent(), InteractionComponent()])
Expand Down
7 changes: 4 additions & 3 deletions test/languagemap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import unittest

if __name__ == '__main__':
Expand Down Expand Up @@ -94,12 +94,13 @@ def test_ToJSONFromJSON(self):
json_str = '{"fr-CA": "CA-test", "en-US": "US-test", "fr-FR": "FR-test"}'
lmap = LanguageMap.from_json(json_str)
self.mapVerificationHelper(lmap)
self.assertEqual(lmap.to_json(), json_str)
self.assertEqual(json.loads(lmap.to_json()), json.loads(json_str))

def test_ToJSON(self):
lmap = LanguageMap({"en-US": "US-test", "fr-CA": "CA-test", "fr-FR": "FR-test"})
# since the map is unordered, it is ok that to_json() changes ordering
self.assertEqual(lmap.to_json(), '{"fr-CA": "CA-test", "en-US": "US-test", "fr-FR": "FR-test"}')
self.assertEqual(json.loads(lmap.to_json()),
json.loads('{"fr-CA": "CA-test", "en-US": "US-test", "fr-FR": "FR-test"}'))

def test_getItemException(self):
lmap = LanguageMap()
Expand Down
16 changes: 11 additions & 5 deletions test/lrs_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
# limitations under the License.

import unittest
import httplib

from six import string_types

try:
import http.client as httplib
except ImportError:
import httplib

if __name__ == '__main__':
from main import setup_tincan_path
Expand Down Expand Up @@ -133,12 +139,12 @@ def test_setters(self):

def test_unicode(self):
resp = LRSResponse()
resp.data = ("\xce\xb4\xce\xbf\xce\xba\xce\xb9\xce\xbc\xce\xae "
"\xcf\x80\xce\xb5\xcf\x81\xce\xb9\xce\xb5\xcf\x87"
"\xce\xbf\xce\xbc\xce\xad\xce\xbd\xce\xbf\xcf\x85")
resp.data = b"\xce\xb4\xce\xbf\xce\xba\xce\xb9\xce\xbc\xce\xae " \
b"\xcf\x80\xce\xb5\xcf\x81\xce\xb9\xce\xb5\xcf\x87" \
b"\xce\xbf\xce\xbc\xce\xad\xce\xbd\xce\xbf\xcf\x85"

self.assertIsInstance(resp, LRSResponse)
self.assertIsInstance(resp.data, unicode)
self.assertIsInstance(resp.data, string_types)
self.assertEqual(resp.data, u"δοκιμή περιεχομένου")

def test_setters_none(self):
Expand Down
3 changes: 2 additions & 1 deletion test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def check_tincan_importability():
try:
import tincan
except ImportError as e:
tincan = None
raise ImportError(
"Could not import tincan."
"\n\n"
Expand Down Expand Up @@ -67,7 +68,7 @@ def setup_tincan_path():
# as that was catching the system installed version, if virtualenv
# is ever implemented for the test suite then this can go away
#
print "Adding %s to PYTHONPATH" % repr(tincan_pardir)
print("Adding %s to PYTHONPATH" % repr(tincan_pardir))
sys.path.insert(1, tincan_pardir)
check_tincan_importability()

Expand Down
Loading

0 comments on commit 92a9721

Please sign in to comment.