Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-activetable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
xblock-activetable
Commits
82ff3556
Commit
82ff3556
authored
Oct 21, 2015
by
Sven Marnach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for activetable.py.
parent
781f858f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
3 deletions
+44
-3
activetable/parsers.py
+3
-2
tests/unit/test_activetable.py
+40
-0
tests/unit/test_parsers.py
+1
-1
No files found.
activetable/parsers.py
View file @
82ff3556
...
...
@@ -92,8 +92,9 @@ def parse_number_list(source):
"""
try
:
lst
=
ast
.
literal_eval
(
source
)
except
SyntaxError
as
exc
:
raise
ParseError
(
exc
.
msg
)
except
(
SyntaxError
,
ValueError
)
as
exc
:
msg
=
getattr
(
exc
,
'msg'
,
getattr
(
exc
,
'message'
,
None
))
raise
ParseError
(
msg
)
if
not
isinstance
(
lst
,
list
):
raise
ParseError
(
'not a list'
)
if
not
all
(
isinstance
(
x
,
numbers
.
Real
)
for
x
in
lst
):
...
...
tests/unit/test_activetable.py
0 → 100644
View file @
82ff3556
# -*- coding: utf-8 -*-
from
__future__
import
absolute_import
,
division
,
unicode_literals
import
unittest
import
mock
from
xblock.field_data
import
DictFieldData
from
xblock.runtime
import
Runtime
from
xblock.validation
import
Validation
from
activetable.activetable
import
ActiveTableXBlock
class
ActiveTableTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
runtime_mock
=
mock
.
Mock
(
spec
=
Runtime
)
self
.
block
=
ActiveTableXBlock
(
self
.
runtime_mock
,
DictFieldData
({}),
mock
.
Mock
())
def
verify_validation
(
self
,
data
,
expect_success
):
validation
=
Validation
(
'xblock_id'
)
self
.
block
.
validate_field_data
(
validation
,
data
)
self
.
assertEqual
(
bool
(
validation
),
expect_success
)
def
test_validate_field_data
(
self
):
data
=
mock
.
Mock
()
data
.
table_definition
=
'invalid'
data
.
column_widths
=
''
data
.
row_heights
=
''
self
.
verify_validation
(
data
,
False
)
data
.
table_definition
=
'[["header"], [6.283]]'
self
.
verify_validation
(
data
,
True
)
data
.
column_widths
=
'invalid'
self
.
verify_validation
(
data
,
False
)
data
.
column_widths
=
'[1, 2, 3]'
self
.
verify_validation
(
data
,
True
)
data
.
row_heights
=
'invalid'
self
.
verify_validation
(
data
,
False
)
data
.
row_heights
=
'[1, 2, 3]'
self
.
verify_validation
(
data
,
True
)
tests/unit/test_parsers.py
View file @
82ff3556
...
...
@@ -52,6 +52,6 @@ class ParserTest(unittest.TestCase):
def
test_parse_number_list
(
self
):
self
.
assertEquals
(
parse_number_list
(
'[1, 2.3]'
),
[
1
,
2.3
])
for
string
in
[
']'
,
'123'
,
'["123"]'
,
'[1j]'
]:
for
string
in
[
']'
,
'123'
,
'["123"]'
,
'[1j]'
,
'malformed'
]:
with
self
.
assertRaises
(
ParseError
):
parse_number_list
(
string
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment