Skip to content

Commit

Permalink
populate notebook with code and markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
duyguHsnHsn committed Jul 24, 2023
1 parent aa859ea commit 24fae57
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { showCreateDeploymentDialog } from './components/DeployJob';
import { showCreateJobDialog } from './components/CreateJob';
import { showDownloadJobDialog } from './components/DownloadJob';
import { showConvertJobToNotebookDialog } from './components/ConvertJobToNotebook';
import { showDeleteJobDialog } from './components/DeleteJob';
import { jobdDataRequest } from './serverRequests';
import { VdkOption } from './vdkOptions/vdk_options';
import { workingDirectory } from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,4 @@ export const populateNotebook = async (notebookContent: JupyterCellProps[], note
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def get_code_structure(self):
return self._code_structure

def get_removed_files(self):
return self._removed_files
return self._removed_files
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ def add_handler(handler, endpoint):
add_handler(CreateDeploymentHandler, "deploy")
add_handler(GetNotebookInfoHandler, "notebook")
add_handler(GetVdkCellIndicesHandler, "vdkCellIndices")
add_handler(GetServerPathHandler, "serverPath")
add_handler(GetServerPathHandler, "serverPath")
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import shutil
import tempfile
import unittest

from vdk_jupyterlab_extension.transform_job import TransformJobDirectoryProcessor


class TestTransformJobDirectoryProcessor(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.sql_content = "SELECT * FROM table"
self.py_content_run = """
def run(job_input: IJobInput):
print("Hello, World!")
"""
self.py_content_without_run = """
def hello():
print("Hello, World!")
"""

with open(os.path.join(self.temp_dir, "test.sql"), "w") as f:
f.write(self.sql_content)
with open(os.path.join(self.temp_dir, "test_run.py"), "w") as f:
f.write(self.py_content_run)
with open(os.path.join(self.temp_dir, "test_without_run.py"), "w") as f:
f.write(self.py_content_without_run)
with open(os.path.join(self.temp_dir, "config.ini"), "w") as f:
pass

self.processor = TransformJobDirectoryProcessor(self.temp_dir)

def tearDown(self):
shutil.rmtree(self.temp_dir)

def test_process_files(self):
self.processor.process_files()
expected_code_structure = [
f'job_input.execute_query("""{self.sql_content}""")',
self.py_content_run,
]
self.assertEqual(self.processor.get_code_structure(), expected_code_structure)
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, "test.sql")))
self.assertFalse(os.path.exists(os.path.join(self.temp_dir, "test_run.py")))
self.assertTrue(
os.path.exists(os.path.join(self.temp_dir, "test_without_run.py"))
)
self.assertTrue(os.path.exists(os.path.join(self.temp_dir, "config.ini")))

expected_removed_files = ["test.sql", "test_run.py"]
self.assertEqual(self.processor.get_removed_files(), expected_removed_files)

def test_get_code_structure(self):
self.processor.process_files()
expected_code_structure = [
f'job_input.execute_query("""{self.sql_content}""")',
self.py_content_run,
]
self.assertEqual(self.processor.get_code_structure(), expected_code_structure)

def test_get_removed_files(self):
self.processor.process_files()
expected_removed_files = ["test.sql", "test_run.py"]
self.assertEqual(self.processor.get_removed_files(), expected_removed_files)
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ def convert_job(job_dir: str):
"removed_files": processor.get_removed_files(),
}
processor.cleanup()
return message
return message

0 comments on commit 24fae57

Please sign in to comment.