test

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package test provides test doubles that implement some of nb interfaces. Authors of nb-extension packages are encouraged to use them as they make for a uniform test code across different packages. See it's example usages in schema/**/*_test.go files.

Index

Constants

This section is empty.

Variables

View Source
var NoWrapper = render.WithCellRenderers(&fakeWrapper{})

NoWrapper overrides the default cell wrapper so that the cell content could be compared directly without parsing the surrounding wrap. Useful for testing extensions.

Functions

func DisplayData

func DisplayData(s, mt string) schema.Cell

DisplayData creates schema.DisplayData cell with source s and reported mime-type mt.

func ErrorOutput

func ErrorOutput(s string) schema.Cell

ErrorOutput creates schema.Error cell with source s and mime-type common.Stderr.

func ExecuteResult

func ExecuteResult(s, mt string, n int) schema.Cell

ExecuteResult creates schema.ExecuteResult cell with source s, reported mime-type mt and execution count n.

func Markdown

func Markdown(s string) schema.Cell

Markdown creates schema.Markdown cell with source s.

func Notebook

func Notebook(cs ...schema.Cell) schema.Notebook

Notebook wraps a slice of cells into a simple schema.Notebook implementation.

func Raw

func Raw(s, mt string) schema.Cell

Raw creates schema.Raw cell with source s and reported mime-type mt.

func Stderr

func Stderr(s string) schema.Cell

Stderr creates schema.Stream cell with source s and mime-type common.Stderr.

func Stdout

func Stdout(s string) schema.Cell

Stdout creates schema.Stream cell with source s and mime-type common.Stdout.

func WithAttachment

func WithAttachment(c schema.Cell, filename string, mimebundle map[string]interface{}) interface {
	schema.Cell
	schema.HasAttachments
}

WithAttachments creates a cell that has an attachment.

The underlying test implementation for schema.MimeBundle accesses its keys in a random order and should always be created with 1 element only to keep test outcomes stable and predictable.

Example:

test.WithAttachments(
	test.Markdown("![img](attachment:photo:png)"),
	"photo.png",
	map[string]interface{"image/png": "base64-encoded-image"}
)

Types

type Cell

type Cell struct {
	CellType schema.CellType
	Mime     string // mime-type (avoid name-clash with the interface method)
	Source   []byte
}

Cell is a test fixture to mock schema.Cell.

func (*Cell) MimeType

func (c *Cell) MimeType() string

func (*Cell) Text

func (c *Cell) Text() []byte

func (*Cell) Type

func (c *Cell) Type() schema.CellType

type CodeCell

type CodeCell struct {
	Cell
	Lang          string
	TimesExecuted int
	Out           []schema.Cell
}

CodeCell is a test fixture to mock schema.CodeCell. Use cases which only require schema.Cell, should create &test.Cell{CT: schema.Code} instead.

func (*CodeCell) ExecutionCount

func (code *CodeCell) ExecutionCount() int

func (*CodeCell) Language

func (code *CodeCell) Language() string

func (*CodeCell) Outputs

func (code *CodeCell) Outputs() []schema.Cell

type ExecuteResultOutput

type ExecuteResultOutput struct {
	Cell
	TimesExecuted int
}

ExecuteResultOutput is a test fixture to mock cell outputs with ExecuteResult type.

func (*ExecuteResultOutput) ExecutionCount

func (ex *ExecuteResultOutput) ExecutionCount() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL