Skip to content

Commit 89199d6

Browse files
author
Zach Lowry
committed
Reformat code according to PEP8.
Add explicit property names for Group, removing appropriate tests. Initialize all fields for properties in __init__. Added long-fill-in interaction type. Changed default date conversion to assume a timestamp, since the existing default called datetime with an invalid parameter.
1 parent 0157d26 commit 89199d6

72 files changed

Lines changed: 794 additions & 446 deletions

Some content is hidden

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

examples/example_script.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# An example script showing the functionality of the TinCanPython Library
22

33
import uuid
4+
45
from resources import lrs_properties
56
from tincan import (
67
RemoteLRS,
@@ -14,6 +15,7 @@
1415
StateDocument,
1516
)
1617

18+
1719
# construct an LRS
1820
print "constructing the LRS..."
1921
lrs = RemoteLRS(
@@ -59,7 +61,7 @@
5961
name='Lord TinCan',
6062
mbox='mailto:lordtincan@tincanapi.com',
6163
),
62-
#language='en-US',
64+
# language='en-US',
6365
)
6466
print "...done"
6567

@@ -105,7 +107,7 @@
105107
# we can query our statements using an object
106108
# constructing the query object with common fields
107109
# note: more information about queries can be found in the API documentation:
108-
# docs/build/html/tincan.html#module-tincan.remote_lrs
110+
# docs/build/html/tincan.html#module-tincan.remote_lrs
109111
query = {
110112
"agent": actor,
111113
"verb": verb,

test/about_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Rustici Software
1+
# Copyright 2014 Rustici Software
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
1616

1717
if __name__ == '__main__':
1818
from main import setup_tincan_path
19+
1920
setup_tincan_path()
2021
from test_utils import TinCanBaseTestCase
2122
from tincan import Version, About
2223

2324

2425
class AboutTest(TinCanBaseTestCase):
25-
2626
def test_defaults(self):
2727
a = About()
2828
self.assertEqual(a.version, [Version.latest])

test/activity_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Rustici Software
1+
# Copyright 2014 Rustici Software
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
if __name__ == '__main__':
1818
from main import setup_tincan_path
19+
1920
setup_tincan_path()
2021
from tincan import (
2122
Activity,
@@ -26,7 +27,6 @@
2627

2728

2829
class ActivityTest(unittest.TestCase):
29-
3030
def test_InitEmpty(self):
3131
activity = Activity()
3232
self.assertIsNone(activity.id)
@@ -95,7 +95,7 @@ def test_ToJSONFromJSON(self):
9595

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

101101
def test_setDefinitionException(self):
@@ -128,6 +128,7 @@ def activityVerificationHelper(self, activity):
128128
self.assertIsInstance(activity.definition, ActivityDefinition)
129129
self.assertEqual(activity.object_type, 'Activity')
130130

131+
131132
if __name__ == '__main__':
132133
suite = unittest.TestLoader().loadTestsFromTestCase(ActivityTest)
133134
unittest.TextTestRunner(verbosity=2).run(suite)

test/activitydefinition_test.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014 Rustici Software
1+
# Copyright 2014 Rustici Software
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,20 +16,32 @@
1616

1717
if __name__ == '__main__':
1818
from main import setup_tincan_path
19+
1920
setup_tincan_path()
2021
from tincan import (
2122
ActivityDefinition,
2223
LanguageMap,
2324
InteractionComponentList,
24-
InteractionComponent,
2525
)
2626

2727

2828
class ActivityDefinitionTest(unittest.TestCase):
29-
3029
def test_InitEmpty(self):
3130
adef = ActivityDefinition()
32-
self.assertEqual(vars(adef), {})
31+
self.assertEqual(vars(adef), {
32+
'_choices': None,
33+
'_correct_responses_pattern': None,
34+
'_description': None,
35+
'_extensions': None,
36+
'_interaction_type': None,
37+
'_more_info': None,
38+
'_name': None,
39+
'_scale': None,
40+
'_source': None,
41+
'_steps': None,
42+
'_target': None,
43+
'_type': None
44+
})
3345
self.assertIsInstance(adef, ActivityDefinition)
3446

3547
def test_InitAll(self):
@@ -43,67 +55,67 @@ def test_InitAll(self):
4355
'choices': InteractionComponentList(),
4456
'scale': InteractionComponentList(),
4557
'source': InteractionComponentList(),
46-
'target':InteractionComponentList(),
58+
'target': InteractionComponentList(),
4759
'steps': InteractionComponentList(),
4860
'extensions': {'test': 'test'}
4961
})
5062
self.definitionVerificationHelper(adef)
5163

5264
def test_InitExceptionType(self):
5365
with self.assertRaises(ValueError):
54-
adef = ActivityDefinition(type='')
66+
ActivityDefinition(type='')
5567

5668
def test_InitExceptionMoreInfo(self):
5769
with self.assertRaises(ValueError):
58-
adef = ActivityDefinition(more_info='')
70+
ActivityDefinition(more_info='')
5971

6072
def test_InitExceptionInteractionType(self):
6173
with self.assertRaises(ValueError):
62-
adef = ActivityDefinition(interaction_type='notvalidinteraction')
74+
ActivityDefinition(interaction_type='notvalidinteraction')
6375

6476
def test_InitExceptionCorrectResponsesPattern(self):
6577
with self.assertRaises(TypeError):
66-
adef = ActivityDefinition(correct_responses_pattern='notlist')
78+
ActivityDefinition(correct_responses_pattern='notlist')
6779

6880
def test_InitExceptionChoices(self):
6981
with self.assertRaises(TypeError):
70-
adef = ActivityDefinition(choices='notlist')
82+
ActivityDefinition(choices='notlist')
7183

7284
def test_InitExceptionChoicesNotComponentList(self):
7385
with self.assertRaises(TypeError):
74-
adef = ActivityDefinition(choices=['not component'])
86+
ActivityDefinition(choices=['not component'])
7587

7688
def test_InitExceptionScale(self):
7789
with self.assertRaises(TypeError):
78-
adef = ActivityDefinition(scale='notlist')
90+
ActivityDefinition(scale='notlist')
7991

8092
def test_InitExceptionScaleNotComponentList(self):
8193
with self.assertRaises(TypeError):
82-
adef = ActivityDefinition(scale=['not component'])
94+
ActivityDefinition(scale=['not component'])
8395

8496
def test_InitExceptionSource(self):
8597
with self.assertRaises(TypeError):
86-
adef = ActivityDefinition(source='notlist')
98+
ActivityDefinition(source='notlist')
8799

88100
def test_InitExceptionSourceNotComponentList(self):
89101
with self.assertRaises(TypeError):
90-
adef = ActivityDefinition(source=['not component'])
102+
ActivityDefinition(source=['not component'])
91103

92104
def test_InitExceptionTarget(self):
93105
with self.assertRaises(TypeError):
94-
adef = ActivityDefinition(target='notlist')
106+
ActivityDefinition(target='notlist')
95107

96108
def test_InitExceptionTargetNotComponentList(self):
97109
with self.assertRaises(TypeError):
98-
adef = ActivityDefinition(target=['not component'])
110+
ActivityDefinition(target=['not component'])
99111

100112
def test_InitExceptionSteps(self):
101113
with self.assertRaises(TypeError):
102-
adef = ActivityDefinition(steps='notlist')
114+
ActivityDefinition(steps='notlist')
103115

104116
def test_InitExceptionStepsNotComponentList(self):
105117
with self.assertRaises(TypeError):
106-
adef = ActivityDefinition(steps=['not component'])
118+
ActivityDefinition(steps=['not component'])
107119

108120
def test_InitUnpack(self):
109121
obj = {
@@ -116,7 +128,7 @@ def test_InitUnpack(self):
116128
'choices': InteractionComponentList(),
117129
'scale': InteractionComponentList(),
118130
'source': InteractionComponentList(),
119-
'target':InteractionComponentList(),
131+
'target': InteractionComponentList(),
120132
'steps': InteractionComponentList(),
121133
'extensions': {'test': 'test'}
122134
}
@@ -125,20 +137,20 @@ def test_InitUnpack(self):
125137

126138
def test_FromJSONExceptionBadJSON(self):
127139
with self.assertRaises(ValueError):
128-
adef = ActivityDefinition.from_json('{"bad JSON"}')
140+
ActivityDefinition.from_json('{"bad JSON"}')
129141

130142
def test_FromJSONExceptionMalformedJSON(self):
131143
with self.assertRaises(AttributeError):
132-
adef = ActivityDefinition.from_json('{"test": "invalid property"}')
144+
ActivityDefinition.from_json('{"test": "invalid property"}')
133145

134146
def test_FromJSONExceptionPartiallyMalformedJSON(self):
135147
with self.assertRaises(AttributeError):
136-
adef = ActivityDefinition.from_json('{"test": "invalid property", "id": \
148+
ActivityDefinition.from_json('{"test": "invalid property", "id": \
137149
"valid property"}')
138150

139151
def test_FromJSONExceptionEmpty(self):
140152
with self.assertRaises(ValueError):
141-
adef = ActivityDefinition.from_json('')
153+
ActivityDefinition.from_json('')
142154

143155
def test_FromJSON(self):
144156
json_str = '{"name":{"en-US":"test"},\

test/activitylist_test.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright 2014 Rustici Software
1+
# Copyright 2014 Rustici Software
22
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
@@ -16,12 +16,12 @@
1616

1717
if __name__ == '__main__':
1818
from main import setup_tincan_path
19+
1920
setup_tincan_path()
2021
from tincan import ActivityList, Activity
2122

2223

2324
class ActivityListTest(unittest.TestCase):
24-
2525
def test_InitNoArgs(self):
2626
alist = ActivityList()
2727
self.assertEqual(alist, [])
@@ -53,7 +53,7 @@ def test_InitActivityList(self):
5353

5454
def test_InitExceptionNotActivity(self):
5555
with self.assertRaises(TypeError):
56-
alist = ActivityList([Activity(), 'not InteractionComponent'])
56+
ActivityList([Activity(), 'not InteractionComponent'])
5757

5858
def test_FromJSON(self):
5959
alist = ActivityList.from_json(
@@ -63,11 +63,11 @@ def test_FromJSON(self):
6363

6464
def test_FromJSONExceptionBadJSON(self):
6565
with self.assertRaises(ValueError):
66-
alist = ActivityList.from_json('{"bad JSON"}')
66+
ActivityList.from_json('{"bad JSON"}')
6767

6868
def test_FromJSONExceptionNestedObject(self):
6969
with self.assertRaises(TypeError):
70-
alist = ActivityList.from_json(
70+
ActivityList.from_json(
7171
'[{"id": "test1"}, [{"id": "nested!"}]]'
7272
)
7373

@@ -87,8 +87,7 @@ def test_AsVersionNotEmpty(self):
8787
alist = ActivityList([a1, a2])
8888
check = alist.as_version()
8989
self.assertEqual(check,
90-
[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]
91-
)
90+
[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}])
9291

9392
def test_ToJSONFromJSON(self):
9493
json_str = '[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]'
@@ -98,7 +97,8 @@ def test_ToJSONFromJSON(self):
9897

9998
def test_ToJSON(self):
10099
alist = ActivityList([{"id": "test1"}, {"id": "test2"}])
101-
self.assertEqual(alist.to_json(), '[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]')
100+
self.assertEqual(alist.to_json(),
101+
'[{"id": "test1", "objectType": "Activity"}, {"id": "test2", "objectType": "Activity"}]')
102102

103103
def test_setItem(self):
104104
alist = ActivityList([Activity(), Activity()])
@@ -177,6 +177,7 @@ def listVerificationHelper(self, alist):
177177
self.assertEqual(alist[0].id, 'test1')
178178
self.assertEqual(alist[1].id, 'test2')
179179

180+
180181
if __name__ == '__main__':
181182
suite = unittest.TestLoader().loadTestsFromTestCase(ActivityListTest)
182183
unittest.TextTestRunner(verbosity=2).run(suite)

0 commit comments

Comments
 (0)