Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase pytest coverage by either adding tests or removing unused code #31

Merged
merged 7 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 47 additions & 19 deletions test_tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
from tsp.response import ResponseStatus
from tsp.tsp_client import TspClient

REQUESTED_TIME_XY_START = 1332170682440133097
REQUESTED_TIME_XY_END = 1332170692664579801
REQUESTED_TIME_XY_LENGTH = 10
REQUESTED_TIME_XY_STEP = (REQUESTED_TIME_XY_END -
REQUESTED_TIME_XY_START) / REQUESTED_TIME_XY_LENGTH
REQUESTED_TIME_START = 1332170682440133097
REQUESTED_TIME_END = 1332170692664579801
REQUESTED_TIME_LENGTH = 10
REQUESTED_TIME_STEP = (REQUESTED_TIME_END -
REQUESTED_TIME_START) / REQUESTED_TIME_LENGTH


class TestTspClient:
Expand Down Expand Up @@ -272,26 +272,39 @@ def test_fetch_xy(self, kernel):
assert response.model is not None
status = response.model.status.upper()

parameters = {}
requested_items = []
for entry in response.model.model.entries:
requested_items.append(entry.id)
parameters[TspClient.REQUESTED_ITEM_KEY] = requested_items

requested_times = []
requested_time = REQUESTED_TIME_XY_START
while len(requested_times) < REQUESTED_TIME_XY_LENGTH:
requested_time += REQUESTED_TIME_XY_STEP
requested_times.append(int(requested_time))
parameters[TspClient.REQUESTED_TIME_KEY] = requested_times

params = {TspClient.PARAMETERS_KEY: parameters}
params = self.__requested_parameters(response)
response = self.tsp_client.fetch_xy(experiment_uuid, output_id, params)
assert response.status_code == 200
assert response.model.model_type == response.model.model_type.XY
self._delete_experiments()
self._delete_traces()

def test_fetch_timegraph_tree_complete(self, kernel):
traces = []
response = self.tsp_client.open_trace(os.path.basename(kernel), kernel)
traces.append(response.model.UUID)
response = self.tsp_client.open_experiment(
os.path.basename(kernel), traces)
assert response.status_code == 200
experiment_uuid = response.model.UUID

response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
output_id = response.model.descriptors[0].id
status = ResponseStatus.RUNNING.name
while status == ResponseStatus.RUNNING.name:
time.sleep(1)
response = self.tsp_client.fetch_timegraph_tree(
experiment_uuid, output_id)
assert response.model is not None
status = response.model.status.upper()

params = self.__requested_parameters(response)
response = self.tsp_client.fetch_timegraph_tree(
experiment_uuid, output_id, params)
assert response.status_code == 200
self._delete_experiments()
self._delete_traces()

def test_fetch_extensions_none(self):
response = self.tsp_client.fetch_extensions()
assert response.status_code == 200
Expand All @@ -314,3 +327,18 @@ def test_posted_extension_deleted(self, extension):

response = self.tsp_client.fetch_extensions()
assert not response.model.extension_set

def __requested_parameters(self, response):
parameters = {}
requested_items = []
for entry in response.model.model.entries:
requested_items.append(entry.id)
parameters[TspClient.REQUESTED_ITEM_KEY] = requested_items

requested_times = []
requested_time = REQUESTED_TIME_START
while len(requested_times) < REQUESTED_TIME_LENGTH:
requested_time += REQUESTED_TIME_STEP
requested_times.append(int(requested_time))
parameters[TspClient.REQUESTED_TIME_KEY] = requested_times
return {TspClient.PARAMETERS_KEY: parameters}
10 changes: 2 additions & 8 deletions tsp/tree_model.py → tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import pandas as pd

from tsp.data_type import DataType


class TreeModel(object):

Expand Down Expand Up @@ -109,13 +107,9 @@ def print(self, data, depth=0):
print(" ", end="")
for _ in range((int)(depth / self._indent) - 1):
print("| ", end="")
other = ""
others = self._entry.others
# TODO print TimeGraphEntry specific fields
for k in others:
other = ('{0} ({1}, {2})'.format(other, k, others.get(k)))
print("{0}{1} ({1}, {2}) {3} {4}".format(
prefix, self._entry.labels[0], self._entry.id, self._entry.parent_id, other))
print("{0}{1} ({1}, {2}) {3}".format(
prefix, self._entry.labels[0], self._entry.id, self._entry.parent_id))
else:
label_str = ""
if(depth > 0):
Expand Down
2 changes: 1 addition & 1 deletion tsp-cli-client
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ from datetime import timedelta
from decimal import Decimal
from os.path import os

from tsp.tree_model import TreeModel
from tree_model import TreeModel
from tsp.tsp_client import TspClient
from tsp.xy_model import XYModel

Expand Down
11 changes: 1 addition & 10 deletions tsp/column_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ColumnDescriptor(object):
Basic entry
'''

def __init__(self, params, copy_others=True):
def __init__(self, params):
'''
Text of header for the entry
'''
Expand All @@ -47,12 +47,3 @@ def __init__(self, params, copy_others=True):
if TOOLTIP_KEY in params:
self.tooltip = params.get(TOOLTIP_KEY)
del params[TOOLTIP_KEY]

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.copy_others = copy_others
if copy_others:
self.others = {}
if params:
self.others = copy.deepcopy(params)
35 changes: 0 additions & 35 deletions tsp/data_type.py

This file was deleted.

11 changes: 1 addition & 10 deletions tsp/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Entry(object):
Basic entry
'''

def __init__(self, params, copy_others=True):
def __init__(self, params):
'''
Unique Id for the entry
'''
Expand Down Expand Up @@ -84,12 +84,3 @@ def __init__(self, params, copy_others=True):
if params.get(STYLE_KEY) is not None:
self.style = OutputElementStyle(params.get(STYLE_KEY))
del params[STYLE_KEY]

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.copy_others = copy_others
if copy_others:
self.others = {}
if params:
self.others = copy.deepcopy(params)
10 changes: 1 addition & 9 deletions tsp/entry_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ def __init__(self, params, model_type=ModelType.XY_TREE):
'''
self.entries = []
if ENTRIES_KEY in params:
entries = params.get(ENTRIES_KEY)
for entry in entries:
for entry in params.get(ENTRIES_KEY):
if model_type == ModelType.TIME_GRAPH_TREE:
self.entries.append(TimeGraphEntry(entry))
else:
self.entries.append(Entry(entry))
del params[ENTRIES_KEY]

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.others = {}
if params:
self.others = copy.deepcopy(params)
19 changes: 6 additions & 13 deletions tsp/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, params):
if UUID_KEY in params:
self.UUID = params.get(UUID_KEY)
del params[UUID_KEY]
else:
else: # pragma: no cover
self.UUID = NA

'''
Expand All @@ -60,7 +60,7 @@ def __init__(self, params):
if NAME_KEY in params:
self.name = params.get(NAME_KEY)
del params[NAME_KEY]
else:
else: # pragma: no cover
self.name = NA

'''
Expand All @@ -69,7 +69,7 @@ def __init__(self, params):
if START_TIME_KEY in params:
self.start = params.get(START_TIME_KEY)
del params[START_TIME_KEY]
else:
else: # pragma: no cover
self.start = -1

'''
Expand All @@ -78,7 +78,7 @@ def __init__(self, params):
if END_TIME_KEY in params:
self.end = params.get(END_TIME_KEY)
del params[END_TIME_KEY]
else:
else: # pragma: no cover
self.end = -1

'''
Expand All @@ -87,7 +87,7 @@ def __init__(self, params):
if NB_EVENT_KEY in params:
self.number_of_events = params.get(NB_EVENT_KEY)
del params[NB_EVENT_KEY]
else:
else: # pragma: no cover
self.number_of_events = 0

'''
Expand All @@ -97,18 +97,11 @@ def __init__(self, params):
if INDEXING_STATUS_KEY in params:
self.indexin_status = params.get(INDEXING_STATUS_KEY)
del params[INDEXING_STATUS_KEY]
else:
else: # pragma: no cover
self.indexin_status = 0

'''
Array of all the traces contained in the experiment
'''
if TRACES_TIME_KEY in params:
self.traces = TraceSet(params.get(TRACES_TIME_KEY))

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.others = {}
if params:
self.others = copy.deepcopy(params)
15 changes: 4 additions & 11 deletions tsp/output_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, params):
if ID_KEY in params:
self.id = params.get(ID_KEY)
del params[ID_KEY]
else:
else: # pragma: no cover
self.id = None

'''
Expand All @@ -60,7 +60,7 @@ def __init__(self, params):
if NAME_KEY in params:
self.name = params.get(NAME_KEY)
del params[NAME_KEY]
else:
else: # pragma: no cover
self.name = UNKOWN

'''
Expand All @@ -69,7 +69,7 @@ def __init__(self, params):
if DESCRIPTION_KEY in params:
self.description = params.get(DESCRIPTION_KEY)
del params[DESCRIPTION_KEY]
else:
else: # pragma: no cover
self.description = UNKOWN

'''
Expand All @@ -79,7 +79,7 @@ def __init__(self, params):
if TYPE_KEY in params:
self.type = params.get(TYPE_KEY)
del params[TYPE_KEY]
else:
else: # pragma: no cover
self.type = UNKOWN

'''
Expand Down Expand Up @@ -127,10 +127,3 @@ def __init__(self, params):
del params[COMPATIBLE_PROVIDERS_KEY]
else:
self.compatible_providers = []

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.others = {}
if params:
self.others = copy.deepcopy(params)
14 changes: 0 additions & 14 deletions tsp/output_element_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ def __init__(self, params):
else:
self.style_values = {}

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.others = {}
if params:
self.others = copy.deepcopy(params)


class OutputStyleModel(object):
'''
Expand All @@ -84,10 +77,3 @@ def __init__(self, params):
del params[STYLES_KEY]
else:
self.style = None

'''
Store other key/value pairs that are not defined in the TSP in a dictionary
'''
self.others = {}
if params:
self.others = copy.deepcopy(params)
6 changes: 3 additions & 3 deletions tsp/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, params, model_type):
self.model = EntryModel(params.get(MODEL_KEY), self.model_type)
elif self.model_type == ModelType.XY_TREE:
self.model = EntryModel(params.get(MODEL_KEY))
elif self.model_type == ModelType.STATES:
elif self.model_type == ModelType.STATES: # pragma: no cover
# TODO
print("not implemented")
elif self.model_type == ModelType.XY:
Expand All @@ -100,13 +100,13 @@ def __init__(self, params, model_type):
'''
if RESPONSE_STATUS_KEY in params:
self.status = ResponseStatus(params.get(RESPONSE_STATUS_KEY))
else:
else: # pragma: no cover
self.status = ResponseStatus.FAILED

'''
Message associated with the response
'''
if STATUS_MESSAGE_KEY in params:
self.status = params.get(STATUS_MESSAGE_KEY)
else:
else: # pragma: no cover
self.status = ""
Loading