[Erp5-report] r40565 lucas - /erp5/trunk/products/ERP5/tests/testSpellChecking.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Nov 23 21:57:59 CET 2010
Author: lucas
Date: Tue Nov 23 21:57:59 2010
New Revision: 40565
URL: http://svn.erp5.org?rev=40565&view=rev
Log:
Improved the test to check all the states of each installed workflow.
Modified:
erp5/trunk/products/ERP5/tests/testSpellChecking.py
Modified: erp5/trunk/products/ERP5/tests/testSpellChecking.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testSpellChecking.py?rev=40565&r1=40564&r2=40565&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testSpellChecking.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testSpellChecking.py [utf8] Tue Nov 23 21:57:59 2010
@@ -2,7 +2,7 @@
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
-# Fabien Morin <fabien at nexedi.com
+# Fabien Morin <fabien at nexedi.com>
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
@@ -27,67 +27,158 @@
##############################################################################
import unittest
-from Products.ERP5.tests.testXHTML import TestXHTML
+from subprocess import Popen, PIPE
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
-import popen2
-class aspell:
- def __init__(self):
- self._f = popen2.Popen3("aspell -l en_GB -a")
- self._f.fromchild.readline() #skip the credit line
- def __call__(self, words):
- words = words.split(' ')
- output = []
- for word in words:
- self._f.tochild.write(word+'\n')
- self._f.tochild.flush()
- s = self._f.fromchild.readline().strip()
- self._f.fromchild.readline() #skip the blank line
- if s == "*":
- output.append(None)
- elif s[0] == '#':
- output.append("No Suggestions")
- else:
- output.append(s.split(':')[1].strip().split(', '))
- return output
+
+# XXX (lucas): this list must be added in text file
+except_word_list = ('todo',
+ 'journalised',)
+
+
+class Aspell(object):
+
+ language_list = ('en_GB',)
+
+ def __call__(self, sentence):
+ word_list = sentence.split()
+ output_dict = {}
+ for word in word_list:
+ if word.lower() in except_word_list:
+ output_dict[word] = ['*']
+ continue
+
+ for language in self.language_list:
+ output_dict[word] = self.getSpellCheckResultList(word, language)
+
+ return output_dict
+
+ def getSpellCheckResultList(self, word, language):
+ command = 'echo %s | aspell -l %s -a' % (word, language)
+ subprocess = Popen(command, shell=True, stdin=PIPE,
+ stdout=PIPE, stderr=PIPE, close_fds=True)
+ return subprocess.communicate()[0].split('\n')[1:]
+
class TestSpellChecking(ERP5TypeTestCase):
run_all_test = 1
- spellChecker = aspell()
+ spellChecker = Aspell()
def getTitle(self):
return "Spell Checking Test"
def getBusinessTemplateList(self):
- return (
- 'erp5_base',)
-
- def validate_spell(self, word):
- '''
- validate the spell. Return True if the word is well spelled, False else,
- whith an error message
- '''
- result = self.spellChecker(word)
- message = ''
- if result != [None] and result != ['No Suggestions']:
- message = '"%s" is missspelled, suggestion are : "%s"' % \
- (word, '", "'.join(result[0]))
- if result == ['No Suggestions']:
- message = '"%s" is missspelled, there is no suggestion.' % word
- return result == [None], message
+ return ('erp5_base',
+ 'erp5_simulation',
+ 'erp5_accounting',
+ 'erp5_pdm',
+ 'erp5_trade',
+ 'erp5_workflow',
+ 'erp5_web',
+
+ 'erp5_ingestion_mysql_innodb_catalog',
+ 'erp5_ingestion',
+ 'erp5_invoicing',
+
+ 'erp5_advanced_invoicing',
+ 'erp5_apparel',
+ 'erp5_archive',
+ #'erp5_banking_cash',
+ #'erp5_banking_check',
+ #'erp5_banking_core',
+ #'erp5_banking_inventory',
+ 'erp5_bpm',
+ 'erp5_budget',
+ 'erp5_calendar',
+
+ 'erp5_commerce',
+ 'erp5_consulting',
+ 'erp5_content_translation',
+ 'erp5_credential',
+ 'erp5_crm',
+ 'erp5_data_protection',
+ 'erp5_dms',
+ #'erp5_egov_catalog',
+ #'erp5_egov',
+ 'erp5_forge',
+ 'erp5_hr',
+ 'erp5_immobilisation',
+ 'erp5_item',
+ 'erp5_knowledge_pad',
+ 'erp5_legacy_tax_system',
+ 'erp5_mrp',
+ 'erp5_open_trade',
+ 'erp5_payroll',
+
+ 'erp5_project',
+ 'erp5_publication',
+ #'erp5_registry_ohada',
+ 'erp5_simulation_performance_test',
+ 'erp5_ui_test',
+
+ 'erp5_wizard',
+ )
+
+ def validate_spell(self, sentence):
+ """
+ Validate the spell. Return True if the word is well spelled, False else,
+ with an error message.
+ """
+ message = '"%s" is misspelled, suggestion are : "%s"'
+ result_dict = {}
+ for word, result_list in self.spellChecker(sentence).iteritems():
+ filtered_result_list = filter(lambda x: x not in ('*', ''), result_list)
+ if filtered_result_list:
+ result_dict[word] = message % (word, \
+ filtered_result_list[0].split(':')[-1].strip())
+ return result_dict
def test_checkSpellChecker(self):
+ """
+ Simple test for Aspell class.
+ """
# check a well spelled world
- self.assertEquals((self.validate_spell('cancelled')), (True, ''))
+ self.assertEquals(self.validate_spell('cancelled'), {})
+ self.assertEquals(self.validate_spell('globally enabled'), {})
+ self.assertEquals(self.validate_spell('http://www.erp5.com'), {})
+ self.assertEquals(self.validate_spell('2010/11/20'), {})
# check some suggestion are given for a small mistake
- self.assertEquals(self.validate_spell('canceled')[0], False)
- self.assertTrue(len(self.validate_spell('canceled')[1]) > 0)
+ self.assertNotEquals(self.validate_spell('canceled'), {})
+ self.assertTrue('is misspelled' in \
+ self.validate_spell('canceled').values()[0])
+
+ def test_business_template_list_with_workflow_template_item(self):
+ """
+ Make sure that we have installed on this test all public
+ business template which has WorkflowTemplateItem.
+ """
+ pass
+
+ def test_spell_check_workflow_states(self):
+ """
+ Running spell check on each state object of all installed workflows.
+ It will check the attributes:
+ - id
+ - title
+ """
+ message = 'State %s: %s, \n Workflow: %s \n Suggestions: %s'
+ attribute_list = ['id', 'title']
+ error_list = []
+ for workflow in self.portal.portal_workflow.objectValues():
+ if getattr(workflow, 'states', None) is not None:
+ for state in workflow.states.objectValues():
+ for attribute in attribute_list:
+ sentence = getattr(state, attribute)
+ result_dict = self.validate_spell(sentence)
+ if result_dict:
+ error_list.append(message % (attribute, sentence, workflow.id, \
+ result_dict.pop(sentence)))
+
+ if error_list:
+ self.fail('\n'.join(error_list))
- # check no suggestion are given for a very bad spelled word
- self.assertEquals(self.validate_spell('cancelefqfdsqfdsfqdsf')[0], False)
- self.assertTrue('no suggestion' in self.validate_spell('cancelefqfdsqfdsfqdsf')[1])
def test_suite():
suite = unittest.TestSuite()
More information about the Erp5-report
mailing list