Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_sample_data(self):
test_array = ["test1", "test2", "test3"]
temp_dir = tempfile.mkdtemp()
inp = inputs.Sketchpad()
out = outputs.Label()
networking.build_template(temp_dir, inp, out)
networking.set_sample_data_in_config_file(temp_dir, test_array)
# We need to come up with a better way so that the config file isn't invalid json unless
# the following parameters are set... (TODO: abidlabs)
networking.set_always_flagged_in_config_file(temp_dir, False)
networking.set_disabled_in_config_file(temp_dir, False)
config_file = os.path.join(temp_dir, 'static/config.json')
with open(config_file) as json_file:
data = json.load(json_file)
self.assertTrue(test_array == data["sample_inputs"])
# If an existing interface is running with this instance, close it.
if self.status == self.STATUS_TYPES["RUNNING"]:
if self.verbose:
print("Closing existing server...")
if self.simple_server is not None:
try:
networking.close_server(self.simple_server)
except OSError:
pass
output_directory = tempfile.mkdtemp()
# Set up a port to serve the directory containing the static files with interface.
server_port, httpd = networking.start_simple_server(self, output_directory)
path_to_local_server = "http://localhost:{}/".format(server_port)
networking.build_template(
output_directory, self.input_interface, self.output_interface
)
networking.set_interface_types_in_config_file(
output_directory,
self.input_interface.__class__.__name__.lower(),
self.output_interface.__class__.__name__.lower(),
)
self.status = self.STATUS_TYPES["RUNNING"]
self.simple_server = httpd
is_colab = False
try: # Check if running interactively using ipython.
from_ipynb = get_ipython()
if "google.colab" in str(from_ipynb):
is_colab = True
# If an existing interface is running with this instance, close it.
if self.status == self.STATUS_TYPES["RUNNING"]:
if self.verbose:
print("Closing existing server...")
if self.simple_server is not None:
try:
networking.close_server(self.simple_server)
except OSError:
pass
output_directory = tempfile.mkdtemp()
# Set up a port to serve the directory containing the static files with interface.
server_port, httpd = networking.start_simple_server(self, output_directory)
path_to_local_server = "http://localhost:{}/".format(server_port)
networking.build_template(
output_directory, self.input_interface, self.output_interface
)
self.update_config_file(output_directory)
self.status = self.STATUS_TYPES["RUNNING"]
self.simple_server = httpd
is_colab = False
try: # Check if running interactively using ipython.
from_ipynb = get_ipython()
if "google.colab" in str(from_ipynb):
is_colab = True
except NameError:
pass