@@ -566,7 +566,7 @@ def test_parse(self):
566566 i , n = 0 , 0
567567 for corpus , a in (("tagged-en-wsj.txt" , (0.968 , 0.945 )), ("tagged-en-oanc.txt" , (0.929 , 0.932 ))):
568568 for sentence in open (os .path .join (PATH , "corpora" , corpus )).readlines ():
569- sentence = sentence .decode ( "utf-8" ). strip ()
569+ sentence = sentence .strip ()
570570 s1 = [w .split ("/" ) for w in sentence .split (" " )]
571571 s2 = [[w for w , pos in s1 ]]
572572 s2 = en .parse (s2 , tokenize = False )
@@ -635,13 +635,13 @@ def test_command_line(self):
635635
636636 # Assert parsed output from the command-line (example from the
637637 # documentation).
638- p = ["python" , "-m" , "pattern.en" , "-s" , "Nice cat." , "-OTCRL" ]
639- p = subprocess .Popen (p , stdout = subprocess .PIPE )
638+ command = ["python" , "-m" , "pattern.en" , "-s" , "Nice cat." , "-OTCRL" ]
639+ p = subprocess .Popen (command , stdout = subprocess .PIPE )
640640 p .wait ()
641641 v = p .stdout .read ()
642642 v = v .strip ()
643643 self .assertEqual (
644- v , "Nice/JJ/B-NP/O/O/nice cat/NN/I-NP/O/O/cat ././O/O/O/." )
644+ v , b "Nice/JJ/B-NP/O/O/nice cat/NN/I-NP/O/O/cat ././O/O/O/." )
645645 print ("python -m pattern.en" )
646646
647647#-------------------------------------------------------------------------
@@ -678,18 +678,19 @@ def test_text(self):
678678 def test_sentence (self ):
679679 # Assert Sentence.
680680 v = self .text [0 ]
681- self .assertTrue (v .start == 0 )
682- self .assertTrue (v .stop == 8 )
683- self .assertTrue (v .string == "I 'm eating pizza with a fork ." )
684- self .assertTrue (v .subjects == [self .text [0 ].chunks [0 ]])
685- self .assertTrue (v .verbs == [self .text [0 ].chunks [1 ]])
686- self .assertTrue (v .objects == [self .text [0 ].chunks [2 ]])
687- self .assertTrue (
688- v .nouns == [self .text [0 ].words [3 ], self .text [0 ].words [6 ]])
681+ self .assertEqual (v .start , 0 )
682+ self .assertEqual (v .stop , 8 )
683+ self .assertEqual (v .string , "I 'm eating pizza with a fork ." )
684+ # TODO may be possible to not list each of these?
685+ self .assertEqual (list (v .subjects ), [self .text [0 ].chunks [0 ]])
686+ self .assertEqual (list (v .verbs ), [self .text [0 ].chunks [1 ]])
687+ self .assertEqual (list (v .objects ), [self .text [0 ].chunks [2 ]])
688+ self .assertEqual (
689+ v .nouns , [self .text [0 ].words [3 ], self .text [0 ].words [6 ]])
689690 # Sentence.string must be unicode.
690- self .assertTrue (isinstance (v .string , unicode ) == True )
691- self .assertTrue (isinstance (unicode (v ), unicode ) == True )
692- self .assertTrue (isinstance (str (v ), str ) == True )
691+ self .assertEqual (isinstance (v .string , unicode ), True )
692+ self .assertEqual (isinstance (unicode (v ), unicode ), True )
693+ self .assertEqual (isinstance (str (v ), str ), True )
693694 print ("pattern.en.Sentence" )
694695
695696 def test_sentence_constituents (self ):
@@ -739,7 +740,7 @@ def test_chunk(self):
739740 # Assert chunk traversal.
740741 self .assertEqual (v .nearest ("VP" ), self .text [0 ].chunks [1 ])
741742 self .assertEqual (v .previous (), self .text [0 ].chunks [1 ])
742- self .assertEqual (next (v ), self .text [0 ].chunks [3 ])
743+ self .assertEqual (v . next (), self .text [0 ].chunks [3 ])
743744 print ("pattern.en.Chunk" )
744745
745746 def test_chunk_conjunctions (self ):
@@ -805,12 +806,6 @@ def test_find(self):
805806 self .assertEqual (v , 11 )
806807 print ("pattern.text.tree.find()" )
807808
808- def test_zip (self ):
809- # Assert list of zipped tuples, using default to balance uneven lists.
810- v = text .tree .zip ([1 , 2 , 3 ], [4 , 5 , 6 , 7 ], default = 0 )
811- self .assertEqual (v , [(1 , 4 ), (2 , 5 ), (3 , 6 ), (0 , 7 )])
812- print ("pattern.text.tree.zip()" )
813-
814809 def test_unzip (self ):
815810 v = text .tree .unzip (1 , [(1 , 4 ), (2 , 5 ), (3 , 6 )])
816811 self .assertEqual (v , [4 , 5 , 6 ])
0 commit comments