Skip to content

Commit

Permalink
Reformat files with ufmt
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed May 16, 2024
1 parent 3a115d1 commit 1ecde4e
Show file tree
Hide file tree
Showing 31 changed files with 1,011 additions and 810 deletions.
189 changes: 99 additions & 90 deletions Analytic_Process.py

Large diffs are not rendered by default.

209 changes: 128 additions & 81 deletions JSON_Schema_Analysis.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions NodeTypes/ArrayNode.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from SchemaNode import SchemaNode


class ArrayNode(SchemaNode):
"""! @brief This class is used to represent JSON Schema arrays as nodes in the schema_graph."""

def __init__(self, name):
## Node's name
self.name = name
Expand All @@ -27,5 +28,3 @@ def getID(self):

def setID(self, id):
self.nodeID = id


16 changes: 8 additions & 8 deletions NodeTypes/KeyValueNode.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from SchemaNode import SchemaNode


class KeyValueNode(SchemaNode):
"""! @brief This class is used to represent Key-Value pairs of JSON Schema Documents as nodes in
the schema graph
A key-value pair looks as follows in the schema document:
@code{.json}
"type" : "string"
@endcode
the schema graph
A key-value pair looks as follows in the schema document:
@code{.json}
"type" : "string"
@endcode
"""

def __init__(self, name, value):
self.name = name
self.value = value
self.nodeID = 0
self.nodeID = 0

def getName(self):
return self.name
Expand All @@ -30,5 +32,3 @@ def getID(self):

def setID(self, id):
self.nodeID = id


7 changes: 4 additions & 3 deletions NodeTypes/ObjectNode.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from SchemaNode import SchemaNode


class ObjectNode(SchemaNode):
"""! @brief Class to represent objects in JSON Schema Documents as Nodes in the schema graph.
"""
"""! @brief Class to represent objects in JSON Schema Documents as Nodes in the schema graph."""

def __init__(self, name):
self.name = name
self.nodeID = 0
Expand All @@ -23,4 +24,4 @@ def getID(self):
return self.nodeID

def setID(self, id):
self.nodeID = id
self.nodeID = id
8 changes: 3 additions & 5 deletions NodeTypes/SchemaNode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import abc


class SchemaNode(abc.ABC):
"""! @brief Abstract class Schema Node for nodes in schema_graph."""

Expand All @@ -10,13 +11,14 @@ def getName(self):
@abc.abstractmethod
def getValue(self):
pass

@abc.abstractclassmethod
def setValue(self, value):
pass

@abc.abstractmethod
def accept(self, visitor):
pass
pass

@abc.abstractmethod
def getID(self):
Expand All @@ -25,7 +27,3 @@ def getID(self):
@abc.abstractmethod
def setID(self, id):
pass




48 changes: 30 additions & 18 deletions PyTest/test_schemagraph.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import sys, pytest
import pytest, sys

sys.path.append("../")
sys.path.append("../NodeTypes")
sys.path.append("../Visitors/")
from schema_graph import schema_graph
import json
import pandas as pd

import networkx as nx
import pandas as pd
from Count_String_Visitor import Count_String_Visitor
from CountReferences_Visitor import CountReferences_Visitor
from schema_graph import schema_graph

"""! @package This file runs the unit test for JSON_Schema_Analysis project
It loads all test cases with files as input and the expected values per category
from the Excel Sheet TestDefintions.xlsx
"""

#getting test data from ExcelSheet
# getting test data from ExcelSheet
xl = pd.ExcelFile("TestDefinitions.xlsx")
df = xl.parse('Tests')
df = xl.parse("Tests")
xl.close()

ex_depth_list = list()
Expand All @@ -43,83 +45,92 @@
filename_list.append(file)
i += 1


@pytest.mark.parametrize("test_input, expected", ex_depth_list)

def test_depth(test_input, expected):
assert depth(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_resdepth_list)

@pytest.mark.parametrize("test_input, expected", ex_resdepth_list)
def test_resolvedDepth(test_input, expected):
assert resDepth(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_has_recursion_list)

@pytest.mark.parametrize("test_input, expected", ex_has_recursion_list)
def test_recursion(test_input, expected):
assert recursion(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_string_count_list)

@pytest.mark.parametrize("test_input, expected", ex_string_count_list)
def test_string_count(test_input, expected):
assert string_count(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_fan_in_list)

@pytest.mark.parametrize("test_input, expected", ex_fan_in_list)
def test_fan_in(test_input, expected):
assert fan_in(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_reachability_list)

@pytest.mark.parametrize("test_input, expected", ex_reachability_list)
def test_reachability(test_input, expected):
assert reachability(test_input) == expected

@pytest.mark.parametrize("test_input, expected", ex_ref_count_list)

@pytest.mark.parametrize("test_input, expected", ex_ref_count_list)
def test_refCount(test_input, expected):
assert refCount(test_input) == expected
assert refCount(test_input) == expected


def depth(filename):
sg = getSg(filename)

return sg.depth_schema()


def resDepth(filename):
sg = getSg(filename)
ret_val = sg.depth_resolvedReferenceGraph()
return ret_val


def recursion(filename):
sg = getSg(filename)

return sg.check_recursion()


def string_count(filename):
sg = getSg(filename)
visitor = Count_String_Visitor()
sg.visit_res_graph(visitor)

return visitor.getCount()


def fan_in(filename):
sg = getSg(filename)

return sg.getMaxFanIn()


def reachability(filename):
sg = getSg(filename)

return sg.check_reachability()


def refCount(filename):
sg = getSg(filename)

return sg.getNoReferences()


def origNodes(filename):
sg = getSg(filename)

return len(list(sg.nodes))


def expNodes(filename):
sg = getSg(filename)

Expand All @@ -131,13 +142,14 @@ def expNodes(filename):

return ret_val


def getSg(filename):
"""! @brief Load Schema Graph from file
@param filename Name of the file located in ./TestSchemas directory
"""! @brief Load Schema Graph from file
@param filename Name of the file located in ./TestSchemas directory
@return schema_graph of the given file
@return schema_graph of the given file
"""
with open("./TestSchemas/"+filename, 'r') as fp:
with open("./TestSchemas/" + filename, "r") as fp:
sg = schema_graph(filename)
sg.load_schema(json.loads(fp.read()))

Expand Down
18 changes: 10 additions & 8 deletions Visitors/AdditionalProperties_Visitor.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
from Visitor import Visitor
from KeyValueNode import KeyValueNode
from Visitor import Visitor


class AdditionalProperties_Visitor(Visitor):
"""! @brief Visitor to count the additionalProperties keyword in the Schema
This visitor counts all appearances of the additionalProperties keyword in the schema.
This visitor counts all appearances of the additionalProperties keyword in the schema.
"""

def __init__(self):
"""! @brief Constructor of AdditionalProperties_Visitor.
It sets the additionalProperties count result value to zero.
It sets the additionalProperties count result value to zero.
"""
self.cnt = 0

def visit(self, node):
"""! @brief Basic visit method implementation.
This function visits a node and increments the counter if the node is a representation
of a additionalProperties keyword in the schema.
This function visits a node and increments the counter if the node is a representation
of a additionalProperties keyword in the schema.
@param node Node to visit. This has to be a inherited type from SchemaNode.
@param node Node to visit. This has to be a inherited type from SchemaNode.
"""
if (node.getName() == "additionalProperties"):
if node.getName() == "additionalProperties":
self.cnt = self.cnt + 1

def getCount(self):
"""! @brief Basic getter for the result value implementation
@return The amount of appearances of additionalProperties keyword in the Schema
@return The amount of appearances of additionalProperties keyword in the Schema
"""
return self.cnt
18 changes: 10 additions & 8 deletions Visitors/AllOf_Visitor.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
from Visitor import Visitor
from KeyValueNode import KeyValueNode
from Visitor import Visitor


class AllOf_Visitor(Visitor):
"""! @brief Visitor to count the allOf keyword in the Schema
This visitor counts all appearances of the allOf keyword in the schema.
This visitor counts all appearances of the allOf keyword in the schema.
"""

def __init__(self):
"""! @brief Constructor of AllOf_Visitor.
It sets the allOf count result value to zero.
It sets the allOf count result value to zero.
"""
self.cnt = 0

def visit(self, node):
"""! @brief Basic visit method implementation.
This function visits a node and increments the counter if the node is a representation
of a allOf keyword in the schema.
This function visits a node and increments the counter if the node is a representation
of a allOf keyword in the schema.
@param node Node to visit. This has to be a inherited type from SchemaNode.
@param node Node to visit. This has to be a inherited type from SchemaNode.
"""
if (node.getName() == "allOf"):
if node.getName() == "allOf":
self.cnt = self.cnt + 1

def getCount(self):
"""! @brief Basic getter for the result value implementation
@return The amount of appearances of allOf keyword in the Schema
@return The amount of appearances of allOf keyword in the Schema
"""
return self.cnt
18 changes: 10 additions & 8 deletions Visitors/AnyOf_Visitor.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
from Visitor import Visitor
from KeyValueNode import KeyValueNode
from Visitor import Visitor


class AnyOf_Visitor(Visitor):
"""! @brief Visitor to count the anyOf keyword in the Schema
This visitor counts all appearances of the anyOf keyword in the schema.
This visitor counts all appearances of the anyOf keyword in the schema.
"""

def __init__(self):
"""! @brief Constructor of AnyOf_Visitor.
It sets the anyOf count result value to zero.
It sets the anyOf count result value to zero.
"""
self.cnt = 0

def visit(self, node):
"""! @brief Basic visit method implementation.
This function visits a node and increments the counter if the node is a representation
of a anyOf keyword in the schema.
This function visits a node and increments the counter if the node is a representation
of a anyOf keyword in the schema.
@param node Node to visit. This has to be a inherited type from SchemaNode.
@param node Node to visit. This has to be a inherited type from SchemaNode.
"""
if (node.getName() == "anyOf"):
if node.getName() == "anyOf":
self.cnt = self.cnt + 1

def getCount(self):
"""! @brief Basic getter for the result value implementation
@return The amount of appearances of anyOf keyword in the Schema
@return The amount of appearances of anyOf keyword in the Schema
"""
return self.cnt
Loading

0 comments on commit 1ecde4e

Please sign in to comment.