-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example for how to use managed test cases with the testing SDK
- Loading branch information
Dan Morton
authored
Apr 4, 2024
1 parent
430c603
commit c7c0581
Showing
8 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import * as flashcardGenerator from './test-suites/flashcard-generator'; | ||
import * as studyGuideOutline from './test-suites/study-guide-outline'; | ||
import * as flashcardGeneratorManaged from './test-suites/flashcard-generator-managed'; | ||
|
||
(async () => { | ||
await Promise.all([flashcardGenerator.run(), studyGuideOutline.run()]); | ||
await Promise.all([ | ||
flashcardGenerator.run(), | ||
studyGuideOutline.run(), | ||
flashcardGeneratorManaged.run(), | ||
]); | ||
})(); |
39 changes: 39 additions & 0 deletions
39
JavaScript/testing-sdk/src/test-suites/flashcard-generator-managed/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { runTestSuite } from '@autoblocks/client/testing'; | ||
import { type TestCase } from '../flashcard-generator/test-cases'; | ||
import { | ||
IsProfessionalTone, | ||
IsSupportedByNotes, | ||
} from '../flashcard-generator/evaluators'; | ||
import { | ||
genFlashcardsFromNotes, | ||
type Flashcard, | ||
} from '../../tasks/flashcard-generator'; | ||
import { AutoblocksAPIClient } from '@autoblocks/client'; | ||
|
||
const TEST_SUITE_ID = 'flashcard-generator-managed'; | ||
|
||
export async function run() { | ||
const inCodeTestCases = [{ notes: 'Initial test case' }]; | ||
let managedTestCases: TestCase[] = []; | ||
|
||
try { | ||
const client = new AutoblocksAPIClient(); | ||
|
||
const response = await client.getTestCases<TestCase>({ | ||
testSuiteId: TEST_SUITE_ID, | ||
}); | ||
managedTestCases = response.testCases.map((testCase) => testCase.body); | ||
} catch { | ||
console.warn('Test suite does not exist yet,'); | ||
} | ||
|
||
await runTestSuite<TestCase, Flashcard[]>({ | ||
id: TEST_SUITE_ID, | ||
testCases: [...managedTestCases, ...inCodeTestCases], | ||
testCaseHash: ['notes'], | ||
evaluators: [new IsProfessionalTone(), new IsSupportedByNotes()], | ||
fn: (args: { testCase: TestCase }) => | ||
genFlashcardsFromNotes(args.testCase.notes), | ||
maxTestCaseConcurrency: 5, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Python/testing-sdk/my_project/test_suites/flashcard_generator_managed/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import List | ||
|
||
from autoblocks.testing.run import run_test_suite | ||
from autoblocks.api.client import AutoblocksAPIClient | ||
|
||
from my_project.tasks.flashcard_generator import Flashcard | ||
from my_project.tasks.flashcard_generator import gen_flashcards_from_notes | ||
|
||
from my_project.test_suites.flashcard_generator.evaluators import IsProfessionalTone | ||
from my_project.test_suites.flashcard_generator.evaluators import IsSupportedByNotes | ||
from my_project.test_suites.flashcard_generator.test_cases import TestCase | ||
|
||
TEST_SUITE_ID = "flashcard-generator-managed" | ||
|
||
|
||
def test_fn(test_case: TestCase) -> List[Flashcard]: | ||
return gen_flashcards_from_notes(test_case.notes) | ||
|
||
|
||
def run() -> None: | ||
in_code_test_cases = [TestCase(notes="Initial test case")] | ||
managed_test_cases = [] | ||
|
||
try: | ||
client = AutoblocksAPIClient() | ||
test_cases_response = client.get_test_cases(test_suite_id=TEST_SUITE_ID) | ||
managed_test_cases = [ | ||
TestCase(**test_case.body) for test_case in test_cases_response.test_cases | ||
] | ||
except: | ||
print("Test suite does not exist yet.") | ||
|
||
run_test_suite( | ||
id=TEST_SUITE_ID, | ||
test_cases=managed_test_cases + in_code_test_cases, | ||
evaluators=[ | ||
IsSupportedByNotes(), | ||
IsProfessionalTone(), | ||
], | ||
fn=test_fn, | ||
max_test_case_concurrency=5, | ||
) |