-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
46 lines (35 loc) · 1.71 KB
/
test.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
__author__ = 'Shalini Aggarwal', 'Nayan Jain'
import unittest
from pyspark.sql import SparkSession
import cngf
from test_data import *
class PySparkTest(unittest.TestCase):
def create_testing_pyspark_session(self):
"""Creates a global pyspark session"""
return (SparkSession.builder.master('local[16]').appName(
'my - local - testing - pyspark - context').getOrCreate())
def test01_setUpClass(self):
"""Sets logging level and creates pyspark session"""
cngf.spark = self.create_testing_pyspark_session()
cngf.spark.sparkContext.setLogLevel("OFF")
def test02_createGraph(self):
"""Creates a dataframe from test.txt file which has the demo data"""
cngf.graph = cngf.create_graph('test.txt', ' ')
self.assertEqual(str(cngf.graph.vertices.collect()), graph_vertices,
msg="Invalid vertices of main graph")
self.assertEqual(str(cngf.graph.edges.collect()), graph_edges,
msg="Invalid edges of main graph")
def test03_process_nodes(self):
"""Verifies that the similarity indices for each node is correct"""
graph_similarity = cngf.node_processing()
self.assertEqual(graph_similarity, similarity_dict, msg="Similarity not"
" equal")
def test04_neighbours(self):
"""Finds and verifies get_neighbours function for the node A"""
neighbours = cngf.get_neighbours('A')
self.assertEqual(neighbours, [u'E', u'B'], msg="Unexpected neighbours")
def test05_tearDownClass(self):
"""Stops the pyspark session"""
cngf.spark.stop()
if __name__ == '__main__':
unittest.main()