Exemplo n.º 1
0
 def test_skipAll(self):
     sp = parse("ABC, ABC, abc, aBc, aBC, aBC, aBC, def")
     self.assertRaises(StopIteration, sp.skip_all, "xyz")
     sp.skip_all(re.compile("ABC"))
     assert sp.__position__ == 8
     sp.skip_all("abc")
     assert sp.__position__ == 33
     self.assertRaises(StopIteration, sp.skip_all, "abc")
Exemplo n.º 2
0
 def test_present(self):
     sp = parse("abc,def,ghi")
     sp.__position__ = 3
     assert sp.present("def")
     assert sp.present("def,")
     assert sp.present("ghi")
     assert not sp.present("weird")
     assert not sp.present("abc")
Exemplo n.º 3
0
 def test_skipAll(self):
     
     sp = parse("ABC, ABC, abc, aBc, aBC, aBC, aBC, def")
     self.assertRaises(StopIteration,sp.skipAll,"xyz")
     sp.skipAll(re.compile("ABC"))
     assert sp.__position__ == 8
     sp.skipAll("abc")
     assert sp.__position__ == 33
     self.assertRaises(StopIteration,sp.skipAll,"abc")
Exemplo n.º 4
0
    def test_lineOperations2(self):
        sp = parse("Hello\n World!")
        sp.__position__ = 2
        sp.rtn()
        assert sp.__position__ == 0

        sp.__position__ = 10
        sp.rtn()
        assert sp.__position__ == 6
Exemplo n.º 5
0
 def test_goto_1(self):
     sp = parse("ABC, Abc, abc, aBc, aBC")
     sp.goto("abC")
     assert sp.__position__ == 0
     sp.goto("aBc")
     assert sp.__position__ == 0
     sp.goto(re.compile("aBc"))
     assert sp.__position__ == 15
     self.assertRaises(StopIteration, sp.goto, "bac")
Exemplo n.º 6
0
 def test_skip(self):
     sp = parse("ABC, Abc, abc, aBc, aBC, aBC, aBC")
     sp.skip("abc")
     assert sp.__position__ == 3
     sp.skip("abc", n=2)
     assert sp.__position__ == 13
     sp.skip(re.compile("aBC"), n=2)
     assert sp.__position__ == 28
     self.assertRaises(StopIteration, sp.skip, re.compile("Abc"))
Exemplo n.º 7
0
 def test_present(self):
     
     sp = parse("abc,def,ghi")
     sp.__position__ = 3
     assert sp.present("def")
     assert sp.present("def,")
     assert sp.present("ghi")
     assert not sp.present("weird")
     assert not sp.present("abc")
Exemplo n.º 8
0
 def test_goto_1(self):
     
     sp = parse("ABC, Abc, abc, aBc, aBC")
     sp.goto("abC")
     assert sp.__position__ == 0
     sp.goto("aBc")
     assert sp.__position__ == 0
     sp.goto(re.compile("aBc"))
     assert sp.__position__ == 15
     self.assertRaises(StopIteration,sp.goto,"bac")
Exemplo n.º 9
0
 def test_distance(self):
     
     sp = parse("abc,def,ghi,abc")
     assert sp.distance("abc") == 0
     assert sp.distance("abc", n = 2) == 12
     self.assertRaises(StopIteration,sp.distance,"abc",n=3)
     assert sp.distance("abc",n=4,default = -1)==-1
     sp.__position__ = 1
     assert sp.distance("abc") == 11
     assert sp.distance("abc", default = -1) == 11
Exemplo n.º 10
0
 def test_lineOperations2(self):
     
     sp = parse("Hello\n World!")
     sp.__position__ = 2
     sp.startOfLine()
     assert sp.__position__ == 0
     
     sp.__position__ = 10
     sp.startOfLine()
     assert sp.__position__ == 6
Exemplo n.º 11
0
 def test_distance(self):
     sp = parse("abc,def,ghi,abc")
     assert sp.distance("abc") == 0
     assert sp.distance("abc", n=2) == 12
     self.assertRaises(StopIteration, sp.distance, "abc", n=3)
     assert sp.distance("abc", n=4, default=-1) == -1
     sp.__position__ = 1
     assert sp.distance("abc") == 11
     assert sp.distance("abc", default=-1) == 11
     assert sp.distance("abc", to="tail") == 14
Exemplo n.º 12
0
 def test_skip(self):
     
     sp = parse("ABC, Abc, abc, aBc, aBC, aBC, aBC")
     sp.skip("abc")
     assert sp.__position__ == 3
     sp.skip("abc", n=2)
     assert sp.__position__ == 13
     sp.skip(re.compile("aBC"), n=2)
     assert sp.__position__ == 28
     self.assertRaises(StopIteration,sp.skip,re.compile("Abc"))
Exemplo n.º 13
0
 def test_nextFloat(self):
     sp = parse("123, 12a3, nan, 5, nan, 4.66, 12., 356.2, 4e-2, 4.e-5, 56.2E-2 -36.6 1.0 2.0 3.0 abc 4.0")
     assert sp.nextFloat() == 123
     testing.assert_equal(sp.nextFloat(2),(12,3))
     assert math.isnan(sp.nextFloat())
     testing.assert_equal(sp.nextFloat(2),(5,float("nan")))
     testing.assert_equal(sp.nextFloat((2,3)),((4.66,12.,356.2),(4e-2,4e-5,56.2e-2)))
     assert sp.nextFloat() == -36.6
     testing.assert_equal(sp.nextFloat("abc"),(1.,2.,3.))
     assert sp.nextFloat() == 4.0        
     self.assertRaises(StopIteration,sp.nextFloat)
Exemplo n.º 14
0
 def test_nextInt(self):
     sp = parse("123abc456 78.8 +45.68-73 1 2 3 4 5 6 7 8 abc 9")
     assert sp.next_int() == 123
     assert sp.next_int() == 456
     assert sp.next_int() == 78
     assert sp.next_int() == 8
     testing.assert_equal(sp.next_int(3), (45, 68, -73))
     testing.assert_equal(sp.next_int((2, 3)), ((1, 2, 3), (4, 5, 6)))
     testing.assert_equal(sp.next_int("abc"), (7, 8))
     assert sp.next_int() == 9
     self.assertRaises(StopIteration, sp.next_int)
Exemplo n.º 15
0
    def test_nextMatch2(self):
        sp = parse("one two2 three, four\n  five   six $")
        x = sp.next_match(cre_word, n="four")
        assert len(x) == 3
        assert x[0] == "one"
        assert x[1] == "two2"
        assert x[2] == "three"

        sp.reset()
        x = sp.next_match(cre_word, n="$")
        assert len(x) == 6
        assert x[-1] == "six"
Exemplo n.º 16
0
 def test_nextInt(self):
     
     sp = parse("123abc456 78.8 +45.68-73 1 2 3 4 5 6 7 8 abc 9")
     assert sp.nextInt() == 123
     assert sp.nextInt() == 456
     assert sp.nextInt() == 78
     assert sp.nextInt() == 8
     testing.assert_equal(sp.nextInt(3),(45,68,-73))
     testing.assert_equal(sp.nextInt((2,3)),((1,2,3),(4,5,6)))
     testing.assert_equal(sp.nextInt("abc"),(7,8))
     assert sp.nextInt() == 9
     self.assertRaises(StopIteration,sp.nextInt)
Exemplo n.º 17
0
 def test_nextMatch(self):
     sp = parse("one two2 three, four\n  five   six seven")
     assert sp.next_match(cre_word) == "one"
     assert sp.__position__ == 3
     assert sp.next_match(cre_word) == "two2"
     assert sp.__position__ == 8
     assert sp.next_match(cre_word) == "three"
     assert sp.next_match(cre_word) == "four"
     assert sp.next_match(cre_word) == "five"
     assert sp.next_match(cre_word) == "six"
     assert sp.next_match(cre_word) == "seven"
     self.assertRaises(StopIteration, sp.next_match, cre_word)
Exemplo n.º 18
0
 def test_nextMatch(self):
     
     sp = parse("one two2 three, four\n  five   six seven")
     assert sp.nextMatch(cre_word) == "one"
     assert sp.__position__ == 3
     assert sp.nextMatch(cre_word) == "two2"
     assert sp.__position__ == 8
     assert sp.nextMatch(cre_word) == "three"
     assert sp.nextMatch(cre_word) == "four"
     assert sp.nextMatch(cre_word) == "five"
     assert sp.nextMatch(cre_word) == "six"
     assert sp.nextMatch(cre_word) == "seven"
     self.assertRaises(StopIteration,sp.nextMatch,cre_word)
Exemplo n.º 19
0
 def test_nextMatch2(self):
     
     sp = parse("one two2 three, four\n  five   six $")
     x = sp.nextMatch(cre_word, n="four")
     assert len(x) == 3
     assert x[0] == "one"
     assert x[1] == "two2"
     assert x[2] == "three"
     
     sp.reset()
     x = sp.nextMatch(cre_word, n="$")
     assert len(x) == 6
     assert x[-1] == "six"
Exemplo n.º 20
0
 def test_pop_save(self):
     
     sp = parse("a, b, c, d, e, f")
     self.assertRaises(Exception, sp.pop)
     sp.save()
     sp.goto("b")
     sp.save()
     sp.goto("c")
     assert sp.__position__ == 6
     sp.pop()
     assert sp.__position__ == 3
     sp.pop()
     assert sp.__position__ == 0
     self.assertRaises(Exception, sp.pop)
Exemplo n.º 21
0
 def test_nextFloat(self):
     sp = parse(
         "123, 12a3, nan, 5, nan, 4.66, 12., 356.2, 4e-2, 4.e-5, 56.2E-2 -36.6 1.0 2.0 3.0 abc 4.0"
     )
     assert sp.next_float() == 123
     testing.assert_equal(sp.next_float(2), (12, 3))
     assert math.isnan(sp.next_float())
     testing.assert_equal(sp.next_float(2), (5, float("nan")))
     testing.assert_equal(sp.next_float((2, 3)),
                          ((4.66, 12., 356.2), (4e-2, 4e-5, 56.2e-2)))
     assert sp.next_float() == -36.6
     testing.assert_equal(sp.next_float("abc"), (1., 2., 3.))
     assert sp.next_float() == 4.0
     self.assertRaises(StopIteration, sp.next_float)
Exemplo n.º 22
0
 def test_goto_0(self):
     
     sp = parse("This is a big string with multiple occurences of this: \"this, this and thIs\".")
     assert sp.__position__ == 0
     sp.goto("is")
     assert sp.__position__ == 2
     sp.goto("is a")
     assert sp.__position__ == 5
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     assert sp.__position__ == len(sp.string)-6
     sp.__position__ += 1
     self.assertRaises(StopIteration,sp.goto,"this")
Exemplo n.º 23
0
 def test_lineOperations(self):
     sp = parse("\none\ntwo\nthree\nfour")
     sp.rtn()
     assert sp.__position__ == 0
     assert sp.next_line() == ""
     assert sp.__position__ == 1
     sp.skip("two")
     sp.rtn()
     assert sp.__position__ == 5
     testing.assert_equal(sp.next_line(2), ("two", "three"))
     assert sp.__position__ == 15
     sp.rtn()
     assert sp.__position__ == 15
     sp.skip("four")
     sp.rtn()
     assert sp.__position__ == 15
     assert sp.next_line() == "four"
     self.assertRaises(StopIteration, sp.next_line)
Exemplo n.º 24
0
 def test_pop_save(self):
     sp = parse("a, b, c, d, e, f")
     self.assertRaises(Exception, sp.pop)
     sp.save()
     sp.goto("b")
     sp.save()
     sp.goto("c")
     assert sp.__position__ == 6
     sp.pop()
     assert sp.__position__ == 3
     sp.pop()
     assert sp.__position__ == 0
     self.assertRaises(Exception, sp.pop)
     sp.fw(12)
     assert sp.__position__ == 12
     sp.fw(4)
     assert sp.__position__ == 16
     self.assertRaises(Exception, sp.fw, 1)
Exemplo n.º 25
0
 def test_goto_0(self):
     sp = parse(
         "This is a big string with multiple occurences of this: \"this, this and thIs\"."
     )
     assert sp.__position__ == 0
     sp.goto("is")
     assert sp.__position__ == 2
     sp.goto("is a")
     assert sp.__position__ == 5
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     sp.__position__ += 1
     sp.goto("this")
     assert sp.__position__ == len(sp.string) - 6
     sp.__position__ += 1
     self.assertRaises(StopIteration, sp.goto, "this")
Exemplo n.º 26
0
 def test_lineOperations(self):
     
     sp = parse("\none\ntwo\nthree\nfour")
     sp.startOfLine()
     assert sp.__position__ == 0
     assert sp.nextLine() == ""
     assert sp.__position__ == 1
     sp.skip("two")
     sp.startOfLine()
     assert sp.__position__ == 5
     testing.assert_equal(sp.nextLine(2), ("two","three"))
     assert sp.__position__ == 15
     sp.startOfLine()
     assert sp.__position__ == 15
     sp.skip("four")
     sp.startOfLine()
     assert sp.__position__ == 15
     assert sp.nextLine() == "four"
     self.assertRaises(StopIteration,sp.nextLine)
Exemplo n.º 27
0
 def test_floatAfter(self):
     sp = parse("value1 = 3; <value2> 3 4.5 5 6 </value2>")
     testing.assert_equal(sp.float_after("<value2>", n="</value2>"),
                          (3, 4.5, 5, 6))
     assert sp.float_after("value1") == 3
Exemplo n.º 28
0
 def test_nextFloat2(self):
     
     sp = parse("123, 456; 789")
     testing.assert_equal(sp.nextFloat(";"),(123, 456))
Exemplo n.º 29
0
 def test_closest(self):
     
     sp = parse("abc,def,ghi")
     assert sp.closest(("g","h","a","b","a")) == 2
     assert sp.closest(("z","x","y")) is None
Exemplo n.º 30
0
 def test_closest2(self):
     
     sp = parse("AbC,dEf,gHI")
     assert sp.closest(("g","h","a","b","a")) == 2
     assert sp.closest(("z","x","y")) is None
Exemplo n.º 31
0
 def test_matchAfter(self):
     
     sp = parse("param1 = value1, param2 value2")
     assert sp.matchAfter("param2",cre_varName)=="value2"
     assert sp.matchAfter("param1",cre_varName)=="value1"
Exemplo n.º 32
0
 def test_intAfter(self):
     sp = parse("cows = 3 rabbits = 5 6")
     testing.assert_equal(sp.int_after("rabbits", n=2), (5, 6))
     assert sp.int_after("cows") == 3
Exemplo n.º 33
0
 def test_nextFloat2(self):
     sp = parse("123, 456; 789")
     testing.assert_equal(sp.next_float(";"), (123, 456))
Exemplo n.º 34
0
 def test_matchAfter(self):
     sp = parse("param1 = value1, param2 value2")
     assert sp.match_after("param2", cre_var_name) == "value2"
     assert sp.match_after("param1", cre_var_name) == "value1"
Exemplo n.º 35
0
 def test_closest2(self):
     sp = parse("AbC,dEf,gHI")
     assert sp.match_closest(("g", "h", "a", "b", "a")) == 2
     assert sp.match_closest(("z", "x", "y")) is None
Exemplo n.º 36
0
 def test_closest(self):
     sp = parse("abc,def,ghi")
     assert sp.match_closest(("g", "h", "a", "b", "a")) == 2
     assert sp.match_closest(("z", "x", "y")) is None
Exemplo n.º 37
0
 def test_intAfter(self):
     
     sp = parse("cows = 3 rabbits = 5 6")
     testing.assert_equal(sp.intAfter("rabbits",n = 2),(5, 6))
     assert sp.intAfter("cows")==3
Exemplo n.º 38
0
 def test_floatAfter(self):
     
     sp = parse("value1 = 3; <value2> 3 4.5 5 6 </value2>")
     testing.assert_equal(sp.floatAfter("<value2>", n = "</value2>"),(3, 4.5, 5, 6))
     assert sp.floatAfter("value1") == 3