Skip to content

Commit e2d1062

Browse files
committed
chore: cleanup
1 parent 061f2fa commit e2d1062

File tree

6 files changed

+70
-50
lines changed

6 files changed

+70
-50
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ or::
100100

101101
$ docker-compose down
102102

103-
will shut down the container and delete non-persistant data.
103+
will shut down the container and delete non-persistent data.
104104

105105
On the first startup run the following command to create the SQLite database.
106106
(Otherwise you will get an error no such table: workbench_xblockstate.)

bin/workbench-make-xblock

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ from __future__ import print_function
66

77
import os
88
import re
9-
import textwrap
109
from builtins import input
1110

1211
from cookiecutter.main import cookiecutter
@@ -54,7 +53,7 @@ def main():
5453

5554
# Find the prototype.
5655
proto_dir = os.path.abspath(os.path.join(__file__, "../../prototype"))
57-
56+
5857
cookiecutter(
5958
proto_dir,
6059
no_input=True,

sample_xblocks/basic/test/test_view_counter.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
from unittest.mock import Mock
6+
67
from xblock.runtime import DictKeyValueStore, KvsFieldData
78
from xblock.test.tools import TestRuntime as Runtime # Workaround for pytest trying to collect "TestRuntime" as a test
89

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from setuptools import setup
88

9+
910
def find_package_data(pkg, data_paths):
1011
"""Generic function to find package_data for `pkg` under `root`."""
1112
data = []

workbench/runtime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import logging
1111
from collections import defaultdict
1212
from datetime import datetime, timedelta
13-
1413
from unittest.mock import Mock
14+
1515
from web_fragments.fragment import Fragment
1616
from xblock.core import XBlockAside
1717
from xblock.exceptions import NoSuchDefinition, NoSuchUsage

workbench/test/test_runtime.py

+65-46
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Test Workbench Runtime"""
22

33

4+
from unittest import TestCase, mock
45

5-
from unittest import TestCase
6-
7-
from unittest import mock
86
import pytest
97
from xblock.fields import Scope
108
from xblock.reference.user_service import UserService
@@ -34,47 +32,59 @@ def test_should_increment(self):
3432

3533
def test_slug_support(self):
3634
self.assertEqual(
37-
self.id_mgr.create_definition("my_block", "my_slug"),
38-
".my_block.my_slug.d0"
35+
self.id_mgr.create_definition("my_block", "my_slug"), ".my_block.my_slug.d0"
3936
)
4037
self.assertEqual(
41-
self.id_mgr.create_definition("my_block", "my_slug"),
42-
".my_block.my_slug.d1"
38+
self.id_mgr.create_definition("my_block", "my_slug"), ".my_block.my_slug.d1"
4339
)
4440

4541
def test_scenario_support(self):
4642
self.test_should_increment()
4743

4844
# Now that we have a scenario, our definition numbering starts over again.
4945
self.id_mgr.set_scenario("my_scenario")
50-
self.assertEqual(self.id_mgr.create_definition("my_block"), "my_scenario.my_block.d0")
51-
self.assertEqual(self.id_mgr.create_definition("my_block"), "my_scenario.my_block.d1")
46+
self.assertEqual(
47+
self.id_mgr.create_definition("my_block"), "my_scenario.my_block.d0"
48+
)
49+
self.assertEqual(
50+
self.id_mgr.create_definition("my_block"), "my_scenario.my_block.d1"
51+
)
5252

5353
self.id_mgr.set_scenario("another_scenario")
54-
self.assertEqual(self.id_mgr.create_definition("my_block"), "another_scenario.my_block.d0")
54+
self.assertEqual(
55+
self.id_mgr.create_definition("my_block"), "another_scenario.my_block.d0"
56+
)
5557

5658
def test_usages(self):
5759
# Now make sure our usages are attached to definitions
5860
self.assertIsNone(self.id_mgr.last_created_usage_id())
5961
self.assertEqual(
6062
self.id_mgr.create_usage("my_scenario.my_block.d0"),
61-
"my_scenario.my_block.d0.u0"
63+
"my_scenario.my_block.d0.u0",
6264
)
6365
self.assertEqual(
6466
self.id_mgr.create_usage("my_scenario.my_block.d0"),
65-
"my_scenario.my_block.d0.u1"
67+
"my_scenario.my_block.d0.u1",
68+
)
69+
self.assertEqual(
70+
self.id_mgr.last_created_usage_id(), "my_scenario.my_block.d0.u1"
6671
)
67-
self.assertEqual(self.id_mgr.last_created_usage_id(), "my_scenario.my_block.d0.u1")
6872

6973
def test_asides(self):
70-
definition_id = self.id_mgr.create_definition('my_block')
74+
definition_id = self.id_mgr.create_definition("my_block")
7175
usage_id = self.id_mgr.create_usage(definition_id)
7276

73-
aside_definition, aside_usage = self.id_mgr.create_aside(definition_id, usage_id, 'my_aside')
77+
aside_definition, aside_usage = self.id_mgr.create_aside(
78+
definition_id, usage_id, "my_aside"
79+
)
7480

75-
self.assertEqual(self.id_mgr.get_aside_type_from_definition(aside_definition), 'my_aside')
76-
self.assertEqual(self.id_mgr.get_definition_id_from_aside(aside_definition), definition_id)
77-
self.assertEqual(self.id_mgr.get_aside_type_from_usage(aside_usage), 'my_aside')
81+
self.assertEqual(
82+
self.id_mgr.get_aside_type_from_definition(aside_definition), "my_aside"
83+
)
84+
self.assertEqual(
85+
self.id_mgr.get_definition_id_from_aside(aside_definition), definition_id
86+
)
87+
self.assertEqual(self.id_mgr.get_aside_type_from_usage(aside_usage), "my_aside")
7888
self.assertEqual(self.id_mgr.get_usage_id_from_aside(aside_usage), usage_id)
7989

8090

@@ -88,24 +98,29 @@ def test_lti_consumer_xblock_requirements(self):
8898
The LTI Consumer XBlock expects a lot of values from the LMS Runtime,
8999
this test ensures that those requirements fulfilled.
90100
"""
91-
runtime = WorkbenchRuntime('test_user')
92-
assert runtime.get_real_user(object()), 'The LTI Consumer XBlock needs this method.'
93-
assert runtime.hostname, 'The LTI Consumer XBlock needs this property.'
94-
assert runtime.anonymous_student_id, 'The LTI Consumer XBlock needs this property.'
101+
runtime = WorkbenchRuntime("test_user")
102+
assert runtime.get_real_user(
103+
object()
104+
), "The LTI Consumer XBlock needs this method."
105+
assert runtime.hostname, "The LTI Consumer XBlock needs this property."
106+
assert (
107+
runtime.anonymous_student_id
108+
), "The LTI Consumer XBlock needs this property."
95109

96110

97111
class TestKVStore(TestCase):
98112
"""
99113
Test the Workbench KVP Store
100114
"""
115+
101116
def setUp(self):
102117
super().setUp()
103118
self.kvs = WorkbenchDjangoKeyValueStore()
104119
self.key = KeyValueStore.Key(
105120
scope=Scope.content,
106121
user_id="rusty",
107122
block_scope_id="my_scenario.my_block.d0",
108-
field_name="age"
123+
field_name="age",
109124
)
110125

111126
@pytest.mark.django_db
@@ -119,11 +134,12 @@ def test_storage(self):
119134

120135

121136
class StubService:
122-
"""Empty service to test loading additional services. """
137+
"""Empty service to test loading additional services."""
123138

124139

125140
class ExceptionService:
126-
"""Stub service that raises an exception on init. """
141+
"""Stub service that raises an exception on init."""
142+
127143
def __init__(self):
128144
raise Exception("Kaboom!")
129145

@@ -138,55 +154,58 @@ def setUp(self):
138154
self.xblock = mock.Mock()
139155

140156
def test_default_services(self):
141-
runtime = WorkbenchRuntime('test_user')
157+
runtime = WorkbenchRuntime("test_user")
142158
self._assert_default_services(runtime)
143159

144-
@mock.patch.dict(settings.WORKBENCH['services'], {
145-
'stub': 'workbench.test.test_runtime.StubService'
146-
})
160+
@mock.patch.dict(
161+
settings.WORKBENCH["services"],
162+
{"stub": "workbench.test.test_runtime.StubService"},
163+
)
147164
def test_settings_adds_services(self):
148-
runtime = WorkbenchRuntime('test_user')
165+
runtime = WorkbenchRuntime("test_user")
149166

150167
# Default services should still be available
151168
self._assert_default_services(runtime)
152169

153170
# An additional service should be provided
154-
self._assert_service(runtime, 'stub', StubService)
171+
self._assert_service(runtime, "stub", StubService)
155172

156173
# Check that the service has the runtime attribute set
157-
service = runtime.service(self.xblock, 'stub')
174+
service = runtime.service(self.xblock, "stub")
158175
self.assertIs(service.runtime, runtime)
159176

160-
@mock.patch.dict(settings.WORKBENCH['services'], {
161-
'not_found': 'workbench.test.test_runtime.NotFoundService'
162-
})
177+
@mock.patch.dict(
178+
settings.WORKBENCH["services"],
179+
{"not_found": "workbench.test.test_runtime.NotFoundService"},
180+
)
163181
def test_could_not_find_service(self):
164-
runtime = WorkbenchRuntime('test_user')
182+
runtime = WorkbenchRuntime("test_user")
165183

166184
# Default services should still be available
167185
self._assert_default_services(runtime)
168186

169187
# The additional service should NOT be available
170-
self.assertIs(runtime.service(self.xblock, 'not_found'), None)
188+
self.assertIs(runtime.service(self.xblock, "not_found"), None)
171189

172-
@mock.patch.dict(settings.WORKBENCH['services'], {
173-
'exception': 'workbench.test.test_runtime.ExceptionService'
174-
})
190+
@mock.patch.dict(
191+
settings.WORKBENCH["services"],
192+
{"exception": "workbench.test.test_runtime.ExceptionService"},
193+
)
175194
def test_runtime_service_initialization_failed(self):
176-
runtime = WorkbenchRuntime('test_user')
195+
runtime = WorkbenchRuntime("test_user")
177196

178197
# Default services should still be available
179198
self._assert_default_services(runtime)
180199

181200
# The additional service should NOT be available
182-
self.assertIs(runtime.service(self.xblock, 'exception'), None)
201+
self.assertIs(runtime.service(self.xblock, "exception"), None)
183202

184203
def _assert_default_services(self, runtime):
185-
"""Check that the default services are available. """
186-
self._assert_service(runtime, 'field-data', KvsFieldData)
187-
self._assert_service(runtime, 'user', UserService)
204+
"""Check that the default services are available."""
205+
self._assert_service(runtime, "field-data", KvsFieldData)
206+
self._assert_service(runtime, "user", UserService)
188207

189208
def _assert_service(self, runtime, service_name, service_class):
190-
"""Check that a service is loaded. """
209+
"""Check that a service is loaded."""
191210
service_instance = runtime.service(self.xblock, service_name)
192211
self.assertIsInstance(service_instance, service_class)

0 commit comments

Comments
 (0)