Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
gh-981: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t92549 committed Jun 21, 2022
1 parent d6fb9f7 commit 1ed4eee
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
22 changes: 13 additions & 9 deletions fish-bowl/fishbowl/fishbowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ def __init__(self, gaffer_connector, generated_directory_path="generated"):
print("To import operations, predicates and functions, use the following command:")
print("from " + generated_directory_path + " import *")

def _write_to_file(self, file_path, data):
with open(file_path, "w+") as file:
file.write(data)

def __generate_library(self):

if os.path.exists(self.generated_directory_path):
shutil.rmtree(self.generated_directory_path)

os.mkdir(self.generated_directory_path)

operations_python = self.__generate_operations()
functions_python = self.__generate_functions("/graph/config/transformFunctions")
predicates_python = self.__generate_functions("/graph/config/filterFunctions")
operations_python = self._generate_operations()
functions_python = self._generate_functions("/graph/config/transformFunctions")
predicates_python = self._generate_functions("/graph/config/filterFunctions")

write_to_file(os.path.join(self.generated_directory_path, "functions.py"), functions_python)
write_to_file(os.path.join(self.generated_directory_path, "predicates.py"), predicates_python)
write_to_file(os.path.join(self.generated_directory_path, "operations.py"), operations_python)
write_to_file(os.path.join(self.generated_directory_path, "__init__.py"),
self._write_to_file(os.path.join(self.generated_directory_path, "functions.py"), functions_python)
self._write_to_file(os.path.join(self.generated_directory_path, "predicates.py"), predicates_python)
self._write_to_file(os.path.join(self.generated_directory_path, "operations.py"), operations_python)
self._write_to_file(os.path.join(self.generated_directory_path, "__init__.py"),
"__all__ = [ \"operations\", \"predicates\", \"functions\" ]\n")

def __generate_functions(self, path):
def _generate_functions(self, path):
# functions is a list of function classes
functions = self._gaffer_connector.get(path)

Expand Down Expand Up @@ -72,7 +76,7 @@ def __generate_functions(self, path):

return "\n".join(functions_python)

def __generate_operations(self):
def _generate_operations(self):
operation_summaries = self._gaffer_connector.get("/graph/operations/details")

operations_python = ["from fishbowl.core import *\n\n"]
Expand Down
24 changes: 2 additions & 22 deletions fish-bowl/fishbowl/util.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
import re
from fishbowl.core import ToJson

"""
Convert string from camelCase to snake_case
"""


# JsonConverter
def camel_to_snake(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()


"""
Write data to a file
"""


def write_to_file(file_path, data):
file = open(file_path, "w+")
file.write(data)
file.close()


"""
Returns a json serializable dictionary based off an object
"""


# Move this
def to_json(obj):
if obj is None:
return None
Expand Down
6 changes: 3 additions & 3 deletions python-shell/src/gafferpy/client/requests_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def perform_request(self, method, target, headers=None, body=None):
raise ConnectionError(
'HTTP error ' + str(error.response.status_code) + ': ' + error.response.text)

## TODO: Fix json transform
if method == "GET":
return response.text

try:
response_json = response.json()
except json.JSONDecodeError:
Expand All @@ -103,7 +105,5 @@ def perform_request(self, method, target, headers=None, body=None):

return g.JsonConverter.from_json(result)

#return response.text

def __del__(self):
self._session.close()
6 changes: 3 additions & 3 deletions python-shell/src/gafferpy/client/urllib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ def perform_request(self, method, target, headers=None, body=None):
error_body)
raise ConnectionError(new_error_string)

## TODO: Fix json transform
response_text = response.read().decode('utf-8')

if method == "GET":
return response_text

if self.verbose:
print('Query response: ' + response_text)

Expand All @@ -70,5 +72,3 @@ def perform_request(self, method, target, headers=None, body=None):
result = None

return g.JsonConverter.from_json(result)

#return response.read().decode('utf-8')

0 comments on commit 1ed4eee

Please sign in to comment.