-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_get_function_data.py
108 lines (90 loc) · 6.36 KB
/
test_get_function_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import unittest
import json
import sys
sys.path.append('../')
import function_data
class TestFunctionData(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Execute the script to update the function data
function_data.get_function_data(output_path='./dataForTesting/test_function_changes.json')
# Load the function changes data
with open('./dataForTesting/test_function_changes.json', 'r') as file:
cls.function_data = json.load(file)['testRepo'] # Access the data within 'testRepo'
def test_createdWithMergeAndNotChangedAfter(self):
# Define the expected function key and content
expected_key = 'blocks/test.js::createdWithMergeAndNotChangedAfter'
expected_function = {
'function_name': 'createdWithMergeAndNotChangedAfter',
'merged_function': "function createdWithMergeAndNotChangedAfter() {\n console.log('This creates the function on test branch')\n console.log('Second change on test branch')\n}",
'changes_after_merge': 0
}
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
self.assertEqual(self.function_data[expected_key]['merged_function'].strip(), expected_function['merged_function'].strip())
self.assertEqual(self.function_data[expected_key]['changes_after_merge'], expected_function['changes_after_merge'])
def test_CreatedOnMainAndNotChangedAfterMerge(self):
# Define the expected function key and content
expected_key = 'blocks/test.js::CreatedOnMainAndNotChangedAfterMerge'
expected_function = {
'function_name': 'CreatedOnMainAndNotChangedAfterMerge',
'merged_function': "function CreatedOnMainAndNotChangedAfterMerge() {\n console.log('This creates the function on main branch')\n console.log('First change on test branch')\n console.log('Second change on test branch')\n}",
'changes_after_merge': 0
}
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
self.assertEqual(self.function_data[expected_key]['merged_function'].strip(), expected_function['merged_function'].strip())
self.assertEqual(self.function_data[expected_key]['changes_after_merge'], expected_function['changes_after_merge'])
def test_createdWithMergeAndChangedAfterMerge(self):
# Define the expected function key and content
expected_key = 'blocks/test.js::createdWithMergeAndChangedAfterMerge'
expected_function = {
'function_name': 'createdWithMergeAndChangedAfterMerge',
'merged_function': "function createdWithMergeAndChangedAfterMerge() {\n console.log('This creates the function on test branch')\n console.log('second change on test branch')\n}",
'changes_after_merge': 1
}
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
self.assertEqual(self.function_data[expected_key]['merged_function'].strip(), expected_function['merged_function'].strip())
self.assertEqual(self.function_data[expected_key]['changes_after_merge'], expected_function['changes_after_merge'])
def test_createdOnMainAndChangedAfterWithMerge(self):
# Define the expected function key and content
expected_key = 'blocks/test.js::createdOnMainAndChangedAfterWithMerge'
expected_function = {
'function_name': 'createdOnMainAndChangedAfterWithMerge',
'merged_function': "function createdOnMainAndChangedAfterWithMerge() {\n console.log('This creates the function on main branch')\n console.log('First change on test branch')\n console.log('Second change on test branch')\n}",
'changes_after_merge': 1
}
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
self.assertEqual(self.function_data[expected_key]['merged_function'].strip(), expected_function['merged_function'].strip())
self.assertEqual(self.function_data[expected_key]['changes_after_merge'], expected_function['changes_after_merge'])
def test_changedAfterMergeWithMerge(self):
# Define the expected function key and content
expected_key = 'blocks/test.js::test_changedAfterMergeWithMerge'
expected_function = {
'function_name': 'test_changedAfterMergeWithMerge',
'merged_function': "function test_changedAfterMergeWithMerge() {\n console.log('This creates the function')\n console.log('Second change on test branch')\n}",
'changes_after_merge': 2
}
# Check if the function data contains the expected function with the correct data
self.assertIn(expected_key, self.function_data)
self.assertEqual(self.function_data[expected_key]['function_name'], expected_function['function_name'])
self.assertEqual(self.function_data[expected_key]['merged_function'].strip(), expected_function['merged_function'].strip())
self.assertEqual(self.function_data[expected_key]['changes_after_merge'], expected_function['changes_after_merge'])
class CustomTestRunner(unittest.TextTestRunner):
def run(self, test):
result = super(CustomTestRunner, self).run(test)
if result.wasSuccessful():
# ANSI escape code for green text
print("\033[92m" + "All tests passed successfully!" + "\033[0m 🚀 🚀 🚀")
return result
if __name__ == '__main__':
unittest.main(testRunner=CustomTestRunner())