Skip to content

Commit

Permalink
feat(protocol-designer): Python generation for the Comment step (#17536)
Browse files Browse the repository at this point in the history
# Overview

This adds Python generation for the Comment step in PD. The Comment step
has not been publicly released yet, but this was easy to implement, so I
might as well get it out of the way.

## Test Plan and Hands on Testing

Added unit tests (for the JSON implementation as well, which didn't seem
to have tests before). Confirmed the output when running from my branch.
Also checked that the generated Python file passes simulation.

## Risk assessment

Very low. Both comments and Python generation are hidden behind feature
flags.
  • Loading branch information
ddcc4 authored Feb 14, 2025
1 parent 41e0f6f commit e3b326e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions step-generation/src/__tests__/comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, it, expect } from 'vitest'
import { comment } from '../commandCreators/atomic/comment'
import { getSuccessResult } from '../fixtures'

describe('comment', () => {
it('should generate comment command', () => {
// InvariantContext and RobotState don't matter for comment.
const invariantContext: any = {}
const robotInitialState: any = {}

const message = 'I am a comment'
const result = comment({ message }, invariantContext, robotInitialState)
const res = getSuccessResult(result)
expect(res.commands).toEqual([
{
commandType: 'comment',
key: expect.any(String),
params: { message },
},
])
expect(res.python).toEqual(`protocol.comment("I am a comment")`)
})
})
4 changes: 3 additions & 1 deletion step-generation/src/commandCreators/atomic/comment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uuid } from '../../utils'
import { uuid, formatPyStr, PROTOCOL_CONTEXT_NAME } from '../../utils'
import type { CommentParams } from '@opentrons/shared-data'
import type { CommandCreator } from '../../types'

Expand All @@ -18,7 +18,9 @@ export const comment: CommandCreator<CommentParams> = (
},
},
]
const python = `${PROTOCOL_CONTEXT_NAME}.comment(${formatPyStr(message)})`
return {
commands,
python,
}
}

0 comments on commit e3b326e

Please sign in to comment.