Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
33013a0b
Commit
33013a0b
authored
Feb 11, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test cases, basic framework for moving id tags out of content_parser
--HG-- branch : pmitros-mod-template
parent
b274c2e2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
3 deletions
+42
-3
courseware/content_parser.py
+8
-1
courseware/modules/__init__.py
+8
-0
courseware/modules/video_module.py
+1
-1
courseware/modules/x_module.py
+1
-1
courseware/tests.py
+24
-0
No files found.
courseware/content_parser.py
View file @
33013a0b
...
...
@@ -8,6 +8,8 @@ from lxml import etree
from
mako.template
import
Template
from
mako.lookup
import
TemplateLookup
#import courseware.modules
try
:
# This lets us do __name__ == ='__main__'
from
django.conf
import
settings
from
student.models
import
UserProfile
...
...
@@ -94,7 +96,12 @@ def id_tag(course):
'tab'
:
'id'
,
'schematic'
:
'id'
,
'book'
:
'id'
}
# TODO:
# alt_ids = courseware.modules.get_default_ids()
# print default_ids, alt_ids
# print default_ids == alt_ids
# Tag elements with unique IDs
elements
=
course
.
xpath
(
"|"
.
join
([
'//'
+
c
for
c
in
default_ids
]))
for
elem
in
elements
:
...
...
courseware/modules/__init__.py
View file @
33013a0b
...
...
@@ -11,6 +11,8 @@ import template_module
import
vertical_module
import
video_module
from
courseware
import
content_parser
# Import all files in modules directory, excluding backups (# and . in name)
# and __init__
#
...
...
@@ -47,3 +49,9 @@ def get_module_id(tag):
def
get_valid_tags
():
return
modx_modules
.
keys
()
def
get_default_ids
():
tags
=
get_valid_tags
()
ids
=
map
(
get_module_id
,
tags
)
return
dict
(
zip
(
tags
,
ids
))
courseware/modules/video_module.py
View file @
33013a0b
...
...
@@ -12,7 +12,7 @@ from x_module import XModule
log
=
logging
.
getLogger
(
"mitx.courseware.modules"
)
class
Module
(
XModule
):
#
id_attribute = 'youtube'
id_attribute
=
'youtube'
video_time
=
0
def
handle_ajax
(
self
,
dispatch
,
get
):
...
...
courseware/modules/x_module.py
View file @
33013a0b
...
...
@@ -8,7 +8,7 @@ class XModule(object):
Initialized on access with __init__, first time with state=None, and
then with state
'''
id_attribute
=
'
name
'
# An attribute guaranteed to be unique
id_attribute
=
'
id
'
# An attribute guaranteed to be unique
@classmethod
def
get_xml_tags
(
c
):
...
...
courseware/tests.py
View file @
33013a0b
import
unittest
import
numpy
import
courseware.modules
import
courseware.capa.calc
as
calc
class
ModelsTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -9,4 +13,24 @@ class ModelsTest(unittest.TestCase):
vc
=
courseware
.
modules
.
get_module_class
(
'video'
)
vc_str
=
"<class 'courseware.modules.video_module.Module'>"
self
.
assertEqual
(
str
(
vc
),
vc_str
)
video_id
=
courseware
.
modules
.
get_default_ids
()[
'video'
]
self
.
assertEqual
(
video_id
,
'youtube'
)
def
test_calc
(
self
):
variables
=
{
'R1'
:
2.0
,
'R3'
:
4.0
}
functions
=
{
'sin'
:
numpy
.
sin
,
'cos'
:
numpy
.
cos
}
self
.
assertEqual
(
calc
.
evaluator
(
variables
,
functions
,
"10000||sin(7+5)-6k"
),
4000.0
)
self
.
assertEqual
(
calc
.
evaluator
({
'R1'
:
2.0
,
'R3'
:
4.0
},
{},
"13"
),
13
)
self
.
assertEqual
(
calc
.
evaluator
(
variables
,
functions
,
"13"
),
13
)
self
.
assertEqual
(
calc
.
evaluator
({
'a'
:
2.2997471478310274
,
'k'
:
9
,
'm'
:
8
,
'x'
:
0.66009498411213041
},
{},
"5"
),
5
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-1"
),
-
1
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-0.33"
),
-.
33
)
self
.
assertEqual
(
calc
.
evaluator
({},{},
"-.33"
),
-.
33
)
exception_happened
=
False
try
:
evaluator
({},{},
"5+7 QWSEKO"
)
except
:
exception_happened
=
True
self
.
assertTrue
(
exception_happened
)
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