示例#1
0
def test_replacement2(engine_contents, engine_locations):
    """Replacement should work"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, 'stmt', 7)
    target2 = (file_name, 'stmt', 5)
    assert not AstorEngine.do_replace(engine_contents, engine_locations,
                                      new_contents, new_locations, target1,
                                      target1)
    assert AstorEngine.do_replace(engine_contents, engine_locations,
                                  new_contents, new_locations, target1,
                                  target2)
    dump = AstorEngine.dump(engine_contents[file_name])
    new_dump = AstorEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -11,7 +11,7 @@
 
 
 def classify_triangle(a, b, c):
-    delay()
+    time.sleep(0.01)
     if a > b:
         tmp = a
         a = b
"""
    assert_diff(dump, new_dump, expected)
示例#2
0
def test_replacement2(engine_contents, engine_locations):
    """Replacement should work"""
    file_name = 'Triangle.java.xml'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, 'expr_stmt', 0)
    target2 = (file_name, 'comment', 0)
    assert not XmlEngine.do_replace(engine_contents, engine_locations,
                                    new_contents, new_locations, target1,
                                    target1)
    assert XmlEngine.do_replace(engine_contents, engine_locations,
                                new_contents, new_locations, target1, target2)
    dump = XmlEngine.dump(engine_contents[file_name])
    new_dump = XmlEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -6,7 +6,7 @@
 
     public static TriangleType classifyTriangle(int a, int b, int c) {
 
-        delay();
+        // Sort the sides so that a <= b <= c
 
         // Sort the sides so that a <= b <= c
         if (a > b) {
"""
    assert_diff(dump, new_dump, expected)
示例#3
0
def test_insertion2(engine_contents, engine_locations):
    """Insertion should be applied in order"""
    file_name = 'Triangle.java.xml'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 10)
    target2 = (file_name, 'expr_stmt', 1)
    target3 = (file_name, 'expr_stmt', 0)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target1, target2)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target1, target3)
    dump = XmlEngine.dump(engine_contents[file_name])
    new_dump = XmlEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -5,6 +5,10 @@
     }
 
     public static TriangleType classifyTriangle(int a, int b, int c) {
+
+        delay();
+
+        a = b;
 
         delay();
 
"""
    assert_diff(dump, new_dump, expected)
示例#4
0
def test_insertion2(engine_contents, engine_locations):
    """Insertion should be applied in order"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 11)
    target2 = (file_name, 'stmt', 5)
    target3 = (file_name, 'stmt', 7)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target2)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target3)
    dump = AstorEngine.dump(engine_contents[file_name])
    new_dump = AstorEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -11,6 +11,8 @@
 
 
 def classify_triangle(a, b, c):
+    delay()
+    time.sleep(0.01)
     delay()
     if a > b:
         tmp = a
"""
    assert_diff(dump, new_dump, expected)
示例#5
0
def test_replacement2(engine_contents, engine_locations):
    """Replacement should work"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, 'line', 14)
    target2 = (file_name, 'line', 15)
    assert not LineEngine.do_replace(engine_contents, engine_locations,
                                     new_contents, new_locations, target1,
                                     target1)
    assert LineEngine.do_replace(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target2)
    dump = LineEngine.dump(engine_contents[file_name])
    new_dump = LineEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -12,7 +12,7 @@
 
 def classify_triangle(a, b, c):
 
-    delay()
+
 
     # Sort the sides so that a <= b <= c
     if a > b:
"""
    assert_diff(dump, new_dump, expected)
示例#6
0
def test_insertion2(engine_contents, engine_locations):
    """Insertion should be applied in order"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_line', 15)
    target2 = (file_name, 'line', 9)
    target3 = (file_name, 'line', 14)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target1, target2)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target1, target3)
    dump = LineEngine.dump(engine_contents[file_name])
    new_dump = LineEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -12,6 +12,8 @@
 
 def classify_triangle(a, b, c):
 
+    delay()
+    time.sleep(0.01)
     delay()
 
     # Sort the sides so that a <= b <= c
     if a > b:
"""
    assert_diff(dump, new_dump, expected)
示例#7
0
def test_insertion3(engine_contents, engine_locations):
    """Insertion locations should be correctly updated"""
    file_name = 'Triangle.java.xml'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 10)
    target2 = (file_name, 'expr_stmt', 1)
    target3 = (file_name, 'expr_stmt', 0)
    target4 = (file_name, '_inter_block', 9)
    target5 = (file_name, '_inter_block', 11)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target1, target2)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target1, target3)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target4, target2)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target5, target2)
    dump = XmlEngine.dump(engine_contents[file_name])
    new_dump = XmlEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -6,9 +6,17 @@
 
     public static TriangleType classifyTriangle(int a, int b, int c) {
 
+        a = b;
+
+        delay();
+
+        a = b;
+
         delay();
 
         // Sort the sides so that a <= b <= c
+
+        a = b;
         if (a > b) {
             int tmp = a;
             a = b;
"""
    assert_diff(dump, new_dump, expected)
示例#8
0
def test_insertion3(engine_contents, engine_locations):
    """Insertion locations should be correctly updated"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 11)
    target2 = (file_name, 'stmt', 5)
    target3 = (file_name, 'stmt', 7)
    target4 = (file_name, '_inter_block', 10)
    target5 = (file_name, '_inter_block', 12)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target2)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target3)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target4, target2)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target5, target2)
    dump = AstorEngine.dump(engine_contents[file_name])
    new_dump = AstorEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -11,11 +11,15 @@
 
 
 def classify_triangle(a, b, c):
+    time.sleep(0.01)
+    delay()
+    time.sleep(0.01)
     delay()
     if a > b:
         tmp = a
         a = b
         b = tmp
+    time.sleep(0.01)
     if a > c:
         tmp = a
         a = c
"""
    assert_diff(dump, new_dump, expected)
示例#9
0
def test_deletion1(engine_contents, engine_locations):
    """Deletion should work"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target = (file_name, 'line', 14)
    assert LineEngine.do_delete(engine_contents, engine_locations,
                                new_contents, new_locations, target)
    dump = LineEngine.dump(engine_contents[file_name])
    new_dump = LineEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -12,7 +12,6 @@
 
 def classify_triangle(a, b, c):
 
-    delay()
 
     # Sort the sides so that a <= b <= c
     if a > b:
"""
    assert_diff(dump, new_dump, expected)
示例#10
0
def test_insertion3(engine_contents, engine_locations):
    """Insertion locations should be correctly updated"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_line', 15)
    target2 = (file_name, 'line', 9)
    target3 = (file_name, 'line', 14)
    target4 = (file_name, '_inter_line', 13)
    target5 = (file_name, '_inter_line', 17)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target1, target2)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target1, target3)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target4, target2)
    assert LineEngine.do_insert(engine_contents, engine_locations,
                                new_contents, new_locations, target5, target2)
    dump = LineEngine.dump(engine_contents[file_name])
    new_dump = LineEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -11,10 +11,14 @@
 
 
 def classify_triangle(a, b, c):
+    time.sleep(0.01)
 
+    delay()
+    time.sleep(0.01)
     delay()
 
     # Sort the sides so that a <= b <= c
+    time.sleep(0.01)
     if a > b:
         tmp = a
         a = b
"""
    assert_diff(dump, new_dump, expected)
示例#11
0
def test_deletion1(engine_contents, engine_locations):
    """Deletion should work"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target = (file_name, 'stmt', 7)
    assert AstorEngine.do_delete(engine_contents, engine_locations,
                                 new_contents, new_locations, target)
    dump = AstorEngine.dump(engine_contents[file_name])
    new_dump = AstorEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -11,7 +11,7 @@
 
 
 def classify_triangle(a, b, c):
-    delay()
+    pass
     if a > b:
         tmp = a
         a = b
"""
    assert_diff(dump, new_dump, expected)
示例#12
0
def test_insertion1(engine_contents, engine_locations):
    """Insertion should work"""
    file_name = 'triangle.py'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 11)
    target2 = (file_name, 'stmt', 5)
    assert AstorEngine.do_insert(engine_contents, engine_locations,
                                 new_contents, new_locations, target1, target2)
    dump = AstorEngine.dump(engine_contents[file_name])
    new_dump = AstorEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -12,6 +12,7 @@
 
 def classify_triangle(a, b, c):
     delay()
+    time.sleep(0.01)
     if a > b:
         tmp = a
         a = b
"""
    assert_diff(dump, new_dump, expected)
示例#13
0
def test_insertion1(engine_contents, engine_locations):
    """Insertion should work"""
    file_name = 'Triangle.java.xml'
    new_contents = copy.deepcopy(engine_contents)
    new_locations = copy.deepcopy(engine_locations)
    target1 = (file_name, '_inter_block', 10)
    target2 = (file_name, 'expr_stmt', 1)
    assert XmlEngine.do_insert(engine_contents, engine_locations, new_contents,
                               new_locations, target1, target2)
    dump = XmlEngine.dump(engine_contents[file_name])
    new_dump = XmlEngine.dump(new_contents[file_name])
    expected = """--- 
+++ 
@@ -7,6 +7,8 @@
     public static TriangleType classifyTriangle(int a, int b, int c) {
 
         delay();
+
+        a = b;
 
         // Sort the sides so that a <= b <= c
         if (a > b) {
"""
    assert_diff(dump, new_dump, expected)