Commit b8548d96 by Sven Marnach

Rename "String" cells to "Text" cells.

parent 41486ac4
......@@ -43,7 +43,7 @@ tolerance specified above. The restrictions for the number of significant digit
well. Significant digits are counted started from the first non-zero digit specified by the
student, and include trailing zeros.
String(answer='<correct answer>')
Text(answer='<correct answer>')
A cell that expects a string answer.
......
......@@ -36,7 +36,7 @@ class ActiveTableXBlock(StudioEditableXBlockMixin, XBlock):
default=textwrap.dedent("""\
[
['Column header 1', 'Column header 2'],
['Enter "answer" here:', String(answer='answer')],
['Enter "answer" here:', Text(answer='answer')],
[42, Numeric(answer=42, tolerance=0.0)],
]
""")
......
......@@ -63,7 +63,7 @@ class NumericCell(Cell):
return abs(value - self.answer) <= self.abs_tolerance
class StringCell(Cell):
class TextCell(Cell):
"""A string response cell."""
placeholder = 'text response'
......
......@@ -5,7 +5,7 @@ from __future__ import absolute_import, division, unicode_literals
import ast
import numbers
from .cells import NumericCell, StaticCell, StringCell
from .cells import NumericCell, StaticCell, TextCell
class ParseError(Exception):
......@@ -63,7 +63,7 @@ def parse_table(table_definition):
def _parse_response_cell(cell_node):
"""Parse a single student response cell definition.
Response cells are written in function call syntax, either String(...) or Numeric(...). All
Response cells are written in function call syntax, either Text(...) or Numeric(...). All
arguments must be keyword arguments.
"""
cell_type = _ensure_type(cell_node.func, ast.Name).id
......@@ -71,8 +71,8 @@ def _parse_response_cell(cell_node):
raise ParseError(
'all arguments to {} must be keyword arguments of the form name=value'.format(cell_type)
)
if cell_type == 'String':
cell_class = StringCell
if cell_type == 'Text':
cell_class = TextCell
kwargs = {kw.arg: _ensure_type(kw.value, ast.Str).s for kw in cell_node.keywords}
elif cell_type == 'Numeric':
cell_class = NumericCell
......
......@@ -3,7 +3,7 @@ from __future__ import absolute_import, division, unicode_literals
import unittest
from activetable.cells import NumericCell, StringCell
from activetable.cells import NumericCell, TextCell
class CellTest(unittest.TestCase):
......@@ -30,9 +30,9 @@ class CellTest(unittest.TestCase):
self.assertFalse(cell.check_response('6.2382'))
def test_string_cell(self):
cell = StringCell('OpenCraft')
cell = TextCell('OpenCraft')
self.assertTrue(cell.check_response('OpenCraft'))
self.assertTrue(cell.check_response(' OpenCraft \t\r\n'))
self.assertFalse(cell.check_response('giraffe'))
cell = StringCell('ÖpenCräft')
cell = TextCell('ÖpenCräft')
self.assertTrue(cell.check_response('ÖpenCräft'))
......@@ -4,7 +4,7 @@ from __future__ import absolute_import, division, unicode_literals
import ddt
import unittest
from activetable.cells import Cell, NumericCell, StaticCell, StringCell
from activetable.cells import Cell, NumericCell, StaticCell, TextCell
from activetable.parsers import ParseError, parse_table, parse_number_list
@ddt.ddt
......@@ -15,12 +15,12 @@ class ParserTest(unittest.TestCase):
[
['Event', 'Year'],
['French Revolution', Numeric(answer=1789)],
['Volcano exploded in 1883', String(answer='Krakatoa')],
['Volcano exploded in 1883', Text(answer='Krakatoa')],
[6.283, 123],
]
"""
thead, tbody = parse_table(table_definition)
expected = eval(table_definition.strip(), dict(Numeric=NumericCell, String=StringCell))
expected = eval(table_definition.strip(), dict(Numeric=NumericCell, Text=TextCell))
expected_body = []
for i, row in enumerate(expected[1:], 1):
cells = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment