Skip to content

Commit

Permalink
Merge pull request #19 from scratchrealm/expand-test-sdk
Browse files Browse the repository at this point in the history
expand test_sdk.py
  • Loading branch information
magland committed Oct 25, 2023
2 parents bacde8a + ef3ecd9 commit 0a695f9
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions python/tests/test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
from protocaas.sdk import App
import os
import shutil
import tempfile
from dataclasses import dataclass
from protocaas.sdk import App, ProcessorBase, InputFile, OutputFile, field


def test_app():
App(
@dataclass
class Processor1Context:
input_file: InputFile = field(help='Input file')
output_file: OutputFile = field(help='Output file')
text1: str = field(help='Text 1', default='abc')
text2: str = field(help='Text 2')
text3: str = field(help='Text 3', default='xyz', options=['abc', 'xyz'])
val1: float = field(help='Value 1', default=1.0)

class Processor1(ProcessorBase):
name = 'processor1'
help = 'This is processor 1'
label = 'Processor 1'
tags = ['processor1', 'test']
attributes = {'test': True}

@staticmethod
def run(context: Processor1Context):
assert context.text1 != ''

app = App(
name='test-app',
help='This is a test app',
app_image='fake-image'
)

app.add_processor(Processor1)

spec = app.get_spec()
assert spec['name'] == 'test-app'

with TemporaryDirectory() as tmpdir:
os.environ['SPEC_OUTPUT_FILE'] = tmpdir + '/spec.json'
app.run()
assert os.path.exists(tmpdir + '/spec.json')

class TemporaryDirectory:
"""A context manager for temporary directories"""
def __init__(self):
self._dir = None
def __enter__(self):
self._dir = tempfile.mkdtemp()
return self._dir
def __exit__(self, exc_type, exc_value, traceback):
if self._dir:
shutil.rmtree(self._dir)

0 comments on commit 0a695f9

Please sign in to comment.