
import unittest

import amara
from amara.lib import util

class Test_util(unittest.TestCase):
    def test_trim_word_count(self):
        x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))


if __name__ == '__main__':
    raise SystemExit("Use nosetests")



import unittest

import amara
from amara.lib import util

class Test_trim_word_count(unittest.TestCase):
    'Testing amara.lib.util.trim_word_count'
    def test_flat_doc(self):
        'Input doc with just top-level text'
        x = amara.parse('<a>one two three four five six seven eight nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))

    def test_nested_doc(self):
        'Input doc with text in nested elements'
        x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))


if __name__ == '__main__':
    raise SystemExit("Use nosetests (nosetests path/to/test/file)")



Expand trim_word_count test a bit
Expand trim_word_count test a bit

- 
  import unittest
  
  import amara
  from amara.lib import util
  
- class Test_util(unittest.TestCase):
+ class Test_trim_word_count(unittest.TestCase):
+     'Testing amara.lib.util.trim_word_count'
-     def test_trim_word_count(self):
+     def test_flat_doc(self):
+         'Input doc with just top-level text'
+         x = amara.parse('<a>one two three four five six seven eight nine</a>')
+         for i in range(1, 11):
+             trimmed_tree = util.trim_word_count(x, i)
+             word_count = len(trimmed_tree.xml_select(u'string(.)').split())
+             self.assertEquals(word_count, min(i, 9))
+ 
+     def test_nested_doc(self):
+         'Input doc with text in nested elements'
          x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
          for i in range(1, 11):
              trimmed_tree = util.trim_word_count(x, i)
              word_count = len(trimmed_tree.xml_select(u'string(.)').split())
              self.assertEquals(word_count, min(i, 9))
  
  
  if __name__ == '__main__':
-     raise SystemExit("Use nosetests")
+     raise SystemExit("Use nosetests (nosetests path/to/test/file)")
  
  
  
Expand trim_word_count test a bit
## Code Before:

import unittest

import amara
from amara.lib import util

class Test_util(unittest.TestCase):
    def test_trim_word_count(self):
        x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))


if __name__ == '__main__':
    raise SystemExit("Use nosetests")



## Instruction:
Expand trim_word_count test a bit
## Code After:
import unittest

import amara
from amara.lib import util

class Test_trim_word_count(unittest.TestCase):
    'Testing amara.lib.util.trim_word_count'
    def test_flat_doc(self):
        'Input doc with just top-level text'
        x = amara.parse('<a>one two three four five six seven eight nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))

    def test_nested_doc(self):
        'Input doc with text in nested elements'
        x = amara.parse('<a>one two <b>three four </b><c>five <d>six seven</d> eight</c> nine</a>')
        for i in range(1, 11):
            trimmed_tree = util.trim_word_count(x, i)
            word_count = len(trimmed_tree.xml_select(u'string(.)').split())
            self.assertEquals(word_count, min(i, 9))


if __name__ == '__main__':
    raise SystemExit("Use nosetests (nosetests path/to/test/file)")


