Skip to content

Commit a0917d3

Browse files
authored
Merge pull request #101 from stopic13/master
Adding python 3 support
2 parents 424eeda + 37febbe commit a0917d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+431
-545
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: python
22
python:
3-
- "2.7"
4-
install: easy_install aniso8601 pytz
3+
- "3.6"
4+
install: pip3 install aniso8601 pytz
55
before_script:
66
- cd test
77
- cp resources/lrs_properties.py.travis-ci resources/lrs_properties.py
8-
script: python main.py
8+
script: python3 main.py

README.md

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,14 @@ For more information about the Tin Can API visit:
1010

1111
<http://tincanapi.com/>
1212

13-
Requires Python 2.7 or later.
13+
Requires Python 3.6 or later.
1414

1515
## Installation
16-
TinCanPython requires [Python 2.7](https://www.python.org/downloads/) or later. Python 3 is not supported.
16+
TinCanPython requires [Python 3.6](https://www.python.org/downloads/) or later.
1717

1818
If you are installing from the Github repo, you will need to install `aniso8601` and `pytz` (use `sudo` as necessary):
1919

20-
easy_install aniso8601 pytz
21-
22-
### Recommended optimization
23-
To speed up the timezone lookups, run:
24-
25-
pip unzip pytz
20+
pip3 install aniso8601 pytz
2621

2722
## Testing
2823
The preferred way to run the tests is from the command line.
@@ -45,23 +40,23 @@ It is possible to run all the tests in one go, or just run one part of the tests
4540
1. `cd` to the `test` directory.
4641
2. Run
4742

48-
python main.py
43+
python3 main.py
4944

5045
#### One of the tests:
51-
1. `cd` to the directory containing the test.
46+
1. `cd` to the root directory.
5247
2. Run
5348

54-
python result_test.py
49+
python3 -m unittest test.remote_lrs_test
50+
Where "remote_lrs_test.py" is the test file you want to run
5551

56-
(or whatever test you want to run)
5752

5853
#### A single test case of one of the tests:
59-
1. `cd` to the directory containing the test.
54+
1. `cd` to the root directory.
6055
2. Run
6156

62-
python -m unittest remote_lrs_test.RemoteLRSTest.test_retrieve_statement
57+
python3 -m unittest test.remote_lrs_test.RemoteLRSTest.test_save_statements
6358

64-
Where "remote_lrs_test" is the test file, "RemoteLRSTest" is the class in that file, and "test_retrieve_statement" is the specific test case.
59+
Where "remote_lrs_test" is the test file, "RemoteLRSTest" is the class in that file, and "test_save_statements" is the specific test case.
6560

6661
## API doc generation
6762
To automatically generate documentation, at the root of the repository run,
@@ -103,22 +98,18 @@ Update setup.py to contain the correct release version and any other new informa
10398

10499
To test the register/upload, run the following commands in the repo directory:
105100

106-
python setup.py register -r pypitest
107-
python setup.py sdist upload -r pypitest
101+
python3 setup.py register -r pypitest
102+
python3 setup.py sdist upload -r pypitest
108103

109104
You should get no errors and should be able to find this tincan version at https://testpypi.python.org/pypi.
110105

111106
To register/upload to the live PyPI server, run the following commands in the repo directory:
112107

113-
python setup.py register -r pypi
114-
python setup.py sdist upload -r pypi
108+
python3 setup.py register -r pypi
109+
python3 setup.py sdist upload -r pypi
115110

116-
The new module should be now be installable with pip or easy_install.
117-
118-
easy_install tincan
119-
120-
or
111+
The new module should be now be installable with pip.
121112

122-
pip install tincan
113+
pip3 install tincan
123114

124115
Use sudo as necessary.

examples/example_script.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import uuid
44

5-
from resources import lrs_properties
5+
from test.resources import lrs_properties
66
from tincan import (
77
RemoteLRS,
88
Statement,
@@ -17,44 +17,44 @@
1717

1818

1919
# construct an LRS
20-
print "constructing the LRS..."
20+
print("constructing the LRS...")
2121
lrs = RemoteLRS(
2222
version=lrs_properties.version,
2323
endpoint=lrs_properties.endpoint,
2424
username=lrs_properties.username,
2525
password=lrs_properties.password,
2626
)
27-
print "...done"
27+
print("...done")
2828

2929
# construct the actor of the statement
30-
print "constructing the Actor..."
30+
print("constructing the Actor...")
3131
actor = Agent(
3232
name='UserMan',
3333
mbox='mailto:[email protected]',
3434
)
35-
print "...done"
35+
print("...done")
3636

3737
# construct the verb of the statement
38-
print "constructing the Verb..."
38+
print("constructing the Verb...")
3939
verb = Verb(
4040
id='http://adlnet.gov/expapi/verbs/experienced',
4141
display=LanguageMap({'en-US': 'experienced'}),
4242
)
43-
print "...done"
43+
print("...done")
4444

4545
# construct the object of the statement
46-
print "constructing the Object..."
46+
print("constructing the Object...")
4747
object = Activity(
4848
id='http://tincanapi.com/TinCanPython/Example/0',
4949
definition=ActivityDefinition(
5050
name=LanguageMap({'en-US': 'TinCanPython Library'}),
5151
description=LanguageMap({'en-US': 'Use of, or interaction with, the TinCanPython Library'}),
5252
),
5353
)
54-
print "...done"
54+
print("...done")
5555

5656
# construct a context for the statement
57-
print "constructing the Context..."
57+
print("constructing the Context...")
5858
context = Context(
5959
registration=uuid.uuid4(),
6060
instructor=Agent(
@@ -63,46 +63,46 @@
6363
),
6464
# language='en-US',
6565
)
66-
print "...done"
66+
print("...done")
6767

6868
# construct the actual statement
69-
print "constructing the Statement..."
69+
print("constructing the Statement...")
7070
statement = Statement(
7171
actor=actor,
7272
verb=verb,
7373
object=object,
7474
context=context,
7575
)
76-
print "...done"
76+
print("...done")
7777

7878
# save our statement to the remote_lrs and store the response in 'response'
79-
print "saving the Statement..."
79+
print("saving the Statement...")
8080
response = lrs.save_statement(statement)
8181

8282
if not response:
8383
raise ValueError("statement failed to save")
84-
print "...done"
84+
print("...done")
8585

8686
# retrieve our statement from the remote_lrs using the id returned in the response
87-
print "Now, retrieving statement..."
87+
print("Now, retrieving statement...")
8888
response = lrs.retrieve_statement(response.content.id)
8989

9090
if not response.success:
9191
raise ValueError("statement could not be retrieved")
92-
print "...done"
92+
print("...done")
9393

94-
print "constructing new Statement from retrieved statement data..."
94+
print("constructing new Statement from retrieved statement data...")
9595
ret_statement = response.content
96-
print "...done"
96+
print("...done")
9797

9898
# now, using our old statement and our returned statement, we can send multiple statements
9999
# note: these statements are logically identical, but are 2 separate objects
100-
print "saving both Statements"
100+
print("saving both Statements")
101101
response = lrs.save_statements([statement, ret_statement])
102102

103103
if not response:
104104
raise ValueError("statements failed to save")
105-
print "...done"
105+
print("...done")
106106

107107
# we can query our statements using an object
108108
# constructing the query object with common fields
@@ -117,26 +117,26 @@
117117
"limit": 2,
118118
}
119119

120-
print "querying statements..."
120+
print("querying statements...")
121121
response = lrs.query_statements(query)
122122

123123
if not response:
124124
raise ValueError("statements could not be queried")
125-
print "...done"
125+
print("...done")
126126

127127
# now we will explore saving a document, e.g. a state document
128-
print "constructing a state document..."
128+
print("constructing a state document...")
129129
state_document = StateDocument(
130130
activity=object,
131131
agent=actor,
132132
id='stateDoc',
133133
content=bytearray('stateDocValue', encoding='utf-8'),
134134
)
135-
print "...done"
135+
print("...done")
136136

137-
print "saving state document..."
137+
print("saving state document...")
138138
response = lrs.save_state(state_document)
139139

140140
if not response.success:
141141
raise ValueError("could not save state document")
142-
print "...done"
142+
print("...done")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'tincan/conversions',
88
'tincan/documents',
99
],
10-
version='0.0.5',
10+
version='1.0.0',
1111
description='A Python library for implementing Tin Can API.',
1212
author='Rustici Software',
1313
author_email='mailto:[email protected]',

test/about_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import unittest
1616

1717
if __name__ == '__main__':
18-
from main import setup_tincan_path
18+
from test.main import setup_tincan_path
1919

2020
setup_tincan_path()
21-
from test_utils import TinCanBaseTestCase
21+
from test.test_utils import TinCanBaseTestCase
2222
from tincan import Version, About
2323

2424

test/activity_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import json
1515
import unittest
1616

1717
if __name__ == '__main__':
18-
from main import setup_tincan_path
18+
from test.main import setup_tincan_path
1919

2020
setup_tincan_path()
2121
from tincan import (
@@ -91,12 +91,12 @@ def test_ToJSONFromJSON(self):
9191
check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
9292
activity = Activity.from_json(json_str)
9393
self.activityVerificationHelper(activity)
94-
self.assertEqual(activity.to_json(), check_str)
94+
self.assertEqual(json.loads(activity.to_json()), json.loads(check_str))
9595

9696
def test_ToJSON(self):
9797
check_str = '{"definition": {}, "id": "test", "objectType": "Activity"}'
9898
activity = Activity(**{'id': 'test', 'definition': {}, 'object_type': 'Activity'})
99-
self.assertEqual(activity.to_json(), check_str)
99+
self.assertEqual(json.loads(activity.to_json()), json.loads(check_str))
100100

101101
def test_setDefinitionException(self):
102102
activity = Activity()

test/activitydefinition_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import json
1515
import unittest
1616

1717
if __name__ == '__main__':
18-
from main import setup_tincan_path
18+
from test.main import setup_tincan_path
1919

2020
setup_tincan_path()
2121
from tincan import (
@@ -215,7 +215,7 @@ def test_ToJSONIgnoreNone(self):
215215
'description': {'en-US': 'test'},
216216
'more_info': None
217217
})
218-
self.assertEqual(adef.to_json(), '{"description": {"en-US": "test"}}')
218+
self.assertEqual(json.loads(adef.to_json()), json.loads('{"description": {"en-US": "test"}}'))
219219

220220
def test_ToJSONEmpty(self):
221221
adef = ActivityDefinition()

test/activitylist_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import json
1515
import unittest
1616

1717
if __name__ == '__main__':
18-
from main import setup_tincan_path
18+
from test.main import setup_tincan_path
1919

2020
setup_tincan_path()
2121
from tincan import ActivityList, Activity
@@ -93,12 +93,13 @@ def test_ToJSONFromJSON(self):
9393
json_str = '[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]'
9494
alist = ActivityList.from_json(json_str)
9595
self.listVerificationHelper(alist)
96-
self.assertEqual(alist.to_json(), json_str)
96+
self.assertEqual(json.loads(alist.to_json()), json.loads(json_str))
9797

9898
def test_ToJSON(self):
9999
alist = ActivityList([{"id": "test1"}, {"id": "test2"}])
100-
self.assertEqual(alist.to_json(),
101-
'[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]')
100+
self.assertEqual(json.loads(alist.to_json()),
101+
json.loads(
102+
'[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]'))
102103

103104
def test_setItem(self):
104105
alist = ActivityList([Activity(), Activity()])

test/agent_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import unittest
1616

1717
if __name__ == '__main__':
18-
from main import setup_tincan_path
18+
from test.main import setup_tincan_path
1919

2020
setup_tincan_path()
2121
from tincan import Agent, AgentAccount

0 commit comments

Comments
 (0)