Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ease
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
ease
Commits
5dbcad33
Commit
5dbcad33
authored
Dec 09, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #47 from edx/will/tempdir-fix
Will/tempdir fix
parents
42f95138
2b66d6b0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
11 deletions
+64
-11
ease/tests/test_spellcheck.py
+46
-0
ease/util_functions.py
+18
-11
No files found.
ease/tests/test_spellcheck.py
0 → 100644
View file @
5dbcad33
from
unittest
import
TestCase
from
nose.tools
import
assert_equal
from
mock
import
patch
from
ease.util_functions
import
spell_correct
class
SpellCheckUnitTest
(
TestCase
):
"""
Test that spell-check works correctly.
"""
def
test_all_correct
(
self
):
self
.
_assert_spell
(
"The quick brown dog jumped over the lazy fox."
,
"The quick brown dog jumped over the lazy fox."
,
0
,
"The quick brown dog jumped over the lazy fox."
)
def
test_some_misspelled
(
self
):
self
.
_assert_spell
(
"The quuick brown dog jimped over the lazy fox."
,
"The quick brown dog jumped over the lazy fox."
,
2
,
"The <bs>quuick</bs> brown dog <bs>jimped</bs> over the lazy fox."
,
)
def
test_empty_str
(
self
):
self
.
_assert_spell
(
""
,
""
,
0
,
""
)
def
test_unicode
(
self
):
self
.
_assert_spell
(
"The quick brown dog jimped over the
\u00FC
ber fox."
,
"The quick brown dog jumped over the
\u00FC
ber fox."
,
2
,
"The quick brown dog <bs>jimped</bs> over the
\u00FC
ber fox."
,
)
@patch
(
"util_functions.os.popen"
)
def
test_aspell_not_found
(
self
,
popen_mock
):
# Expected behavior when aspell is not installed is to return the original
# string with no corrections.
popen_mock
.
side_effect
=
OSError
self
.
_assert_spell
(
"Test striiing"
,
"Test striiing"
,
0
,
"Test striiing"
)
def
_assert_spell
(
self
,
input_str
,
expected_str
,
expected_num_changed
,
expected_markup
):
result
=
spell_correct
(
input_str
)
assert_equal
(
result
,
(
expected_str
,
expected_num_changed
,
expected_markup
))
ease/util_functions.py
View file @
5dbcad33
...
...
@@ -13,6 +13,7 @@ import nltk
import
pickle
import
logging
import
sys
import
tempfile
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -84,20 +85,27 @@ def spell_correct(string):
string - string
"""
#Create a temp file so that aspell could be used
f
=
open
(
'tmpfile'
,
'w'
)
# Create a temp file so that aspell could be used
# By default, tempfile will delete this file when the file handle is closed.
f
=
tempfile
.
NamedTemporaryFile
(
mode
=
'w'
)
f
.
write
(
string
)
f
.
flush
()
f_path
=
os
.
path
.
abspath
(
f
.
name
)
f
.
close
()
try
:
p
=
os
.
popen
(
aspell_path
+
" -a < "
+
f_path
+
" --sug-mode=ultra"
)
except
:
log
.
exception
(
"Could not find aspell, so could not spell correct!"
)
#Return original string if aspell fails
# Aspell returns a list of incorrect words with the above flags
incorrect
=
p
.
readlines
()
p
.
close
()
except
Exception
:
log
.
exception
(
"aspell process failed; could not spell check"
)
# Return original string if aspell fails
return
string
,
0
,
string
#Aspell returns a list of incorrect words with the above flags
incorrect
=
p
.
readlines
()
p
.
close
()
finally
:
f
.
close
()
incorrect_words
=
list
()
correct_spelling
=
list
()
for
i
in
range
(
1
,
len
(
incorrect
)):
...
...
@@ -487,4 +495,4 @@ def getMedian(numericValues):
lower
=
theValues
[
len
(
theValues
)
/
2
-
1
]
upper
=
theValues
[
len
(
theValues
)
/
2
]
return
(
float
(
lower
+
upper
))
/
2
\ No newline at end of file
return
(
float
(
lower
+
upper
))
/
2
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