Skip to content

Commit

Permalink
feat: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashankar committed Dec 8, 2024
1 parent f8598b4 commit 8b443bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
31 changes: 7 additions & 24 deletions tests/test_runner_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def temp_intermediate_dir():
yield tmpdirname


def create_pipeline(input_file, output_file, intermediate_dir, operation_prompt):
def create_pipeline(input_file, output_file, intermediate_dir, operation_prompt, bypass_cache=False):
return Pipeline(
name="test_pipeline",
datasets={"test_input": Dataset(type="file", path=input_file)},
Expand All @@ -45,6 +45,7 @@ def create_pipeline(input_file, output_file, intermediate_dir, operation_prompt)
type="map",
prompt=operation_prompt,
output={"schema": {"result": "string"}},
bypass_cache=bypass_cache,
)
],
steps=[
Expand Down Expand Up @@ -80,34 +81,16 @@ def test_pipeline_rerun_on_operation_change(
# Check that the pipeline was not rerun (cost should be zero)
assert unmodified_cost == 0

# Record the start time
start_time = time.time()

# Run again without changes
_ = pipeline.run()

# Record the end time
end_time = time.time()

# Calculate and store the runtime
unmodified_runtime = end_time - start_time

# Modify the operation
modified_prompt = "Count the words in the following text: '{{ input.text }}'"
modified_pipeline = create_pipeline(
temp_input_file, temp_output_file, temp_intermediate_dir, modified_prompt
temp_input_file, temp_output_file, temp_intermediate_dir, modified_prompt, bypass_cache=True
)

# Record the start time
start_time = time.time()

_ = modified_pipeline.run()

# Record the end time
end_time = time.time()
modified_cost = modified_pipeline.run()

# Calculate and store the runtime
modified_runtime = end_time - start_time


# Check that the intermediate files were updated
with open(
Expand All @@ -116,8 +99,8 @@ def test_pipeline_rerun_on_operation_change(
intermediate_data = json.load(f)
assert any("word" in str(item).lower() for item in intermediate_data)

# Check that the runtime is faster when not modifying
assert unmodified_runtime < modified_runtime * 2
# Check that the cost > 0
assert modified_cost > 0


# Test with an incorrect later operation but correct earlier operation
Expand Down
8 changes: 4 additions & 4 deletions website/src/app/playground/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const CodeEditorPipelineApp: React.FC = () => {
const handleSaveAs = async () => {
try {
// Collect all localStorage data
const data: Record<string, any> = {};
const data: Record<string, unknown> = {};
Object.values(localStorageKeys).forEach((key) => {
const value = localStorage.getItem(key);
if (value) {
Expand Down Expand Up @@ -554,7 +554,7 @@ const CodeEditorPipelineApp: React.FC = () => {
<ResizablePanel defaultSize={60} minSize={30} className="h-full">
<ResizablePanelGroup direction="vertical" className="h-full">
<ResizablePanel
defaultSize={70}
defaultSize={60}
minSize={5}
className="overflow-auto"
>
Expand All @@ -565,7 +565,7 @@ const CodeEditorPipelineApp: React.FC = () => {
)}
{showOutput && (
<ResizablePanel
defaultSize={105}
defaultSize={40}
minSize={20}
className="overflow-auto"
>
Expand All @@ -583,7 +583,7 @@ const CodeEditorPipelineApp: React.FC = () => {
minSize={10}
className="h-full overflow-auto"
>
{/* @ts-ignore */}
{/* @ts-expect-error DatasetView expects a specific file type */}
<DatasetView file={currentFile} />
</ResizablePanel>
</>
Expand Down

0 comments on commit 8b443bb

Please sign in to comment.