/test/test_TamilNoun.py

https://gitlab.com/manoj-makkuboy/amuthaa3
Python | 147 lines | 88 code | 32 blank | 27 comment | 4 complexity | 8e8576d29d88df3b49bfb7289339ce94 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/python
  3. # import amuthaa directory from ..
  4. import sys
  5. sys.path.append("..")
  6. sys.path
  7. import unittest
  8. import logging
  9. from amuthaa.TamilNoun import TamilNoun
  10. import xlrd
  11. logging.basicConfig(level=logging.DEBUG)
  12. class TamilNounTest(unittest.TestCase):
  13. """
  14. A test class for the TamilNoun module
  15. """
  16. def setUp(self):
  17. pass
  18. def tearDown(self):
  19. pass
  20. def test_get_class(self):
  21. """ Tests the get_class() method of the TamilNoun class
  22. Loops through words in Excel spreadsheet and ensures that the
  23. get_class() method returns the expected class number for each noun
  24. in the Excel file
  25. """
  26. # Load excel workbook and sheet
  27. filename = "TamilNounsByClass.xls"
  28. wb = xlrd.open_workbook(filename)
  29. sh = wb.sheet_by_index(0)
  30. for rownum in range(1, sh.nrows):
  31. row = sh.row_values(rownum)
  32. noun = row[0]
  33. expected_class = int(row[1])
  34. received_class = int(TamilNoun.get_class(noun))
  35. print(("Testing %s. Expecting class %s..."
  36. % (noun, expected_class)), end=' ')
  37. self.assertEqual(expected_class, received_class,
  38. """For noun %s expected noun class %s.
  39. Received noun class %s."""
  40. % (noun, expected_class, received_class))
  41. print("pass")
  42. def test_split_letters(self):
  43. """ Tests the split_letters() method of the TamilNoun class
  44. Loops through words in Excel spreadsheet and ensures that the
  45. split_letters() method returns the expected list of letters_str
  46. for each noun in the Excel file
  47. """
  48. # Load excel workbook and sheet
  49. filename = "TamilNounsByClass.xls"
  50. wb = xlrd.open_workbook(filename)
  51. sh = wb.sheet_by_index(0)
  52. for rownum in range(1, sh.nrows):
  53. row = sh.row_values(rownum)
  54. noun = row[0]
  55. letters_str = row[3]
  56. letters_str = letters_str.replace(" ", "")
  57. expected_letters = letters_str.split(",")
  58. received_letters = TamilNoun.split_letters(noun)
  59. print(("Testing %s. Expecting letters %s..."
  60. % (noun, letters_str)), end=' ')
  61. self.assertEqual(expected_letters, received_letters,
  62. """For noun %s expected %s.
  63. Received %s."""
  64. % (noun, expected_letters, received_letters))
  65. print("pass")
  66. def test_direct_object(self):
  67. """ Tests the direct_object property's getter method of the
  68. TamilNoun class.
  69. Loops through words in Excel spreadsheet and ensures that the
  70. method returns the expected direct object for each noun in
  71. the Excel file
  72. """
  73. # Load excel workbook and sheet
  74. filename = "TamilNounsByClass.xls"
  75. wb = xlrd.open_workbook(filename)
  76. sh = wb.sheet_by_index(0)
  77. for rownum in range(1, sh.nrows):
  78. row = sh.row_values(rownum)
  79. noun = TamilNoun(row[0])
  80. expected = row[2]
  81. received = noun.direct_object
  82. print(("Testing %s. Expecting %s..."
  83. % (noun.word, expected)), end=' ')
  84. self.assertEqual(expected, received,
  85. """For noun %s expected %s.
  86. Received %s."""
  87. % (noun.word, expected, received))
  88. print("pass")
  89. '''def suite():
  90. suite = unittest.TestSuite()
  91. suite.addTest(unittest.makeSuite(TamilNounTest))
  92. return suite
  93. def main():
  94. runner = unittest.TextTestResult()
  95. test_suite = suite()
  96. runner.run(test_suite) '''
  97. if __name__ == '__main__':
  98. unittest.main()