-
Notifications
You must be signed in to change notification settings - Fork 183
added context methods to the SDK + tests #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+468
−12
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a339b3
added context methods to the SDK + tests
mishushakov 870581c
lint
mishushakov 8f2b1c9
format
mishushakov 699cb05
remove body return on delete context
mishushakov 325cebc
updated tests
mishushakov c6eeca7
updated tests
mishushakov dc14e0f
added 1s delay after context create before list
mishushakov 7306a5a
verify context id
mishushakov 51b0d17
update /contexts method
mishushakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| '@e2b/code-interpreter-python': minor | ||
| '@e2b/code-interpreter': minor | ||
| --- | ||
|
|
||
| added context methods to the sdk |
This file contains hidden or 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 hidden or 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,51 @@ | ||
| import { expect } from 'vitest' | ||
|
|
||
| import { sandboxTest } from './setup' | ||
|
|
||
| sandboxTest('create context with no options', async ({ sandbox }) => { | ||
| const context = await sandbox.createCodeContext() | ||
|
|
||
| const contexts = await sandbox.listCodeContexts() | ||
| const lastContext = contexts[contexts.length - 1] | ||
|
|
||
| expect(lastContext.id).toBeDefined() | ||
| expect(lastContext.language).toBe(context.language) | ||
| expect(lastContext.cwd).toBe(context.cwd) | ||
| }) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sandboxTest('create context with options', async ({ sandbox }) => { | ||
| const context = await sandbox.createCodeContext({ | ||
| language: 'python', | ||
| cwd: '/root', | ||
| }) | ||
|
|
||
| const contexts = await sandbox.listCodeContexts() | ||
| const lastContext = contexts[contexts.length - 1] | ||
|
|
||
| expect(lastContext.id).toBeDefined() | ||
| expect(lastContext.language).toBe(context.language) | ||
| expect(lastContext.cwd).toBe(context.cwd) | ||
| }) | ||
|
|
||
| sandboxTest('remove context', async ({ sandbox }) => { | ||
| const context = await sandbox.createCodeContext() | ||
|
|
||
| await sandbox.removeCodeContext(context.id) | ||
| const contexts = await sandbox.listCodeContexts() | ||
|
|
||
| expect(contexts.map((context) => context.id)).not.toContain(context.id) | ||
| }) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sandboxTest('list contexts', async ({ sandbox }) => { | ||
| const contexts = await sandbox.listCodeContexts() | ||
|
|
||
| // default contexts should include python and javascript | ||
| expect(contexts.map((context) => context.language)).toContain('python') | ||
| expect(contexts.map((context) => context.language)).toContain('javascript') | ||
| }) | ||
|
|
||
| sandboxTest('restart context', async ({ sandbox }) => { | ||
| const context = await sandbox.createCodeContext() | ||
|
|
||
| await sandbox.restartCodeContext(context.id) | ||
| }) | ||
mishushakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| from e2b_code_interpreter.code_interpreter_async import AsyncSandbox | ||
|
|
||
|
|
||
| async def test_create_context_with_no_options(async_sandbox: AsyncSandbox): | ||
| context = await async_sandbox.create_code_context() | ||
|
|
||
| contexts = await async_sandbox.list_code_contexts() | ||
| last_context = contexts[-1] | ||
|
|
||
| assert last_context.id is not None | ||
| assert last_context.language == context.language | ||
| assert last_context.cwd == context.cwd | ||
|
|
||
|
|
||
| async def test_create_context_with_options(async_sandbox: AsyncSandbox): | ||
| context = await async_sandbox.create_code_context( | ||
| language="python", | ||
| cwd="/home/user/test", | ||
| ) | ||
|
|
||
| contexts = await async_sandbox.list_code_contexts() | ||
| last_context = contexts[-1] | ||
|
|
||
| assert last_context.id is not None | ||
| assert last_context.language == context.language | ||
| assert last_context.cwd == context.cwd | ||
|
|
||
|
|
||
| async def test_remove_context(async_sandbox: AsyncSandbox): | ||
| context = await async_sandbox.create_code_context() | ||
|
|
||
| await async_sandbox.remove_code_context(context.id) | ||
|
|
||
|
|
||
| async def test_list_contexts(async_sandbox: AsyncSandbox): | ||
| contexts = await async_sandbox.list_code_contexts() | ||
|
|
||
| # default contexts should include python and javascript | ||
| languages = [context.language for context in contexts] | ||
| assert "python" in languages | ||
| assert "javascript" in languages | ||
|
|
||
|
|
||
| async def test_restart_context(async_sandbox: AsyncSandbox): | ||
| context = await async_sandbox.create_code_context() | ||
|
|
||
| await async_sandbox.restart_code_context(context.id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.