diff --git a/backend/src/apiserver/visualization/exporter.py b/backend/src/apiserver/visualization/exporter.py index 2fe7c55e46b..c5cc3d0f8cc 100644 --- a/backend/src/apiserver/visualization/exporter.py +++ b/backend/src/apiserver/visualization/exporter.py @@ -66,7 +66,10 @@ def create_cell_from_file(filepath: Text) -> NotebookNode: NotebookNode with specified file as code within node. """ - return new_code_cell("%run {}".format(filepath)) + with open(filepath, 'r') as f: + code = f.read() + + return new_code_cell(code) def create_cell_from_custom_code(code: list) -> NotebookNode: diff --git a/backend/src/apiserver/visualization/snapshots/snap_test_exporter.py b/backend/src/apiserver/visualization/snapshots/snap_test_exporter.py index 6d71aa258a5..b5ee9a514af 100644 --- a/backend/src/apiserver/visualization/snapshots/snap_test_exporter.py +++ b/backend/src/apiserver/visualization/snapshots/snap_test_exporter.py @@ -40,7 +40,26 @@ snapshots['TestExporterMethods::test_create_cell_from_custom_code 1'] = '''x = 2 print(x)''' -snapshots['TestExporterMethods::test_create_cell_from_file 1'] = '%run types/tfdv.py' +snapshots['TestExporterMethods::test_create_cell_from_file 1'] = '''""" +test.py provides a basic predefined visualization that can be used for testing +because it does not have dependencies and had a low chance of being updated. +""" + +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +print(2)''' snapshots['TestExporterMethods::test_generate_custom_visualization_html_from_notebook 1'] = '''
@@ -65,24 +84,4 @@ -''' - -snapshots['TestExporterMethods::test_generate_test_visualization_html_from_notebook 1'] = ''' -
-
- - -
- -
- - - -
- -
-
- - - ''' diff --git a/backend/src/apiserver/visualization/test_exporter.py b/backend/src/apiserver/visualization/test_exporter.py index 8022d76cfba..c869fec88e8 100644 --- a/backend/src/apiserver/visualization/test_exporter.py +++ b/backend/src/apiserver/visualization/test_exporter.py @@ -55,7 +55,7 @@ def test_create_cell_from_args_with_multiple_args(self): self.assertMatchSnapshot(html) def test_create_cell_from_file(self): - cell = exporter.create_cell_from_file("types/tfdv.py") + cell = exporter.create_cell_from_file("types/test.py") self.assertMatchSnapshot(cell.source) def test_create_cell_from_custom_code(self): @@ -66,13 +66,6 @@ def test_create_cell_from_custom_code(self): cell = exporter.create_cell_from_custom_code(code) self.assertMatchSnapshot(cell.source) - # Tests to ensure output is generated for predefined visualizations. - def test_generate_test_visualization_html_from_notebook(self): - nb = new_notebook() - nb.cells.append(exporter.create_cell_from_file("types/test.py")) - html = self.exporter.generate_html_from_notebook(nb) - self.assertMatchSnapshot(html) - # Tests to ensure output is generated for custom visualizations. def test_generate_custom_visualization_html_from_notebook(self): nb = new_notebook() diff --git a/backend/src/apiserver/visualization/types/test.py b/backend/src/apiserver/visualization/types/test.py new file mode 100644 index 00000000000..b9eca40d04f --- /dev/null +++ b/backend/src/apiserver/visualization/types/test.py @@ -0,0 +1,20 @@ +""" +test.py provides a basic predefined visualization that can be used for testing +because it does not have dependencies and had a low chance of being updated. +""" + +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +print(2) \ No newline at end of file