Complete core rewrite, with documentation
Still missing documentation about Output core component And actual Action/Targets etc ... in the process of migrating to the new engine
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
from shlax import *
|
||||
|
||||
inner = Run()
|
||||
other = Run('ls')
|
||||
middle = Buildah('alpine', inner, other)
|
||||
outer = Localhost(middle)
|
||||
middle = outer.actions[0]
|
||||
other = middle.actions[1]
|
||||
inner = middle.actions[0]
|
||||
|
||||
|
||||
def test_action_init_args():
|
||||
assert other.args == ('ls',)
|
||||
|
||||
|
||||
def test_action_parent_autoset():
|
||||
assert list(outer.actions) == [middle]
|
||||
assert middle.parent == outer
|
||||
assert inner.parent == middle
|
||||
assert other.parent == middle
|
||||
|
||||
|
||||
def test_action_context():
|
||||
assert outer.context is inner.context
|
||||
assert middle.context is inner.context
|
||||
assert middle.context is outer.context
|
||||
assert other.context is outer.context
|
||||
|
||||
|
||||
def test_action_sibblings():
|
||||
assert inner.sibblings() == [other]
|
||||
assert inner.sibblings(lambda s: s.args[0] == 'ls') == [other]
|
||||
assert inner.sibblings(lambda s: s.args[0] == 'foo') == []
|
||||
assert inner.sibblings(type='run') == [other]
|
||||
assert inner.sibblings(args=('ls',)) == [other]
|
||||
|
||||
|
||||
def test_actions_parents():
|
||||
assert other.parents() == [middle, outer]
|
||||
assert other.parents(lambda p: p.base == 'alpine') == [middle]
|
||||
assert inner.parents(type='localhost') == [outer]
|
||||
assert inner.parents(type='buildah') == [middle]
|
||||
|
||||
|
||||
def test_action_childrens():
|
||||
assert middle.children() == [inner, other]
|
||||
assert middle.children(lambda a: a.args[0] == 'ls') == [other]
|
||||
assert outer.children() == [middle, inner, other]
|
||||
|
||||
|
||||
def test_action_getattr():
|
||||
assert other.exec == middle.exec
|
||||
assert other.shargs == middle.shargs
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
import os
|
||||
|
||||
from shlax import Image
|
||||
from shlax.image import Image
|
||||
|
||||
|
||||
tests = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from shlax import Output
|
||||
from shlax.output import Output
|
||||
|
||||
|
||||
class Write:
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from shlax import *
|
||||
from shlax import proc
|
||||
|
||||
|
||||
test_args_params = [
|
||||
(
|
||||
Localhost(Run('echo hi')),
|
||||
[('sh', '-euc', 'echo hi')]
|
||||
),
|
||||
(
|
||||
Localhost(Run('echo hi', user='jimi')),
|
||||
[('sudo', '-u', 'jimi', 'sh', '-euc', 'echo hi')]
|
||||
),
|
||||
(
|
||||
Localhost(Run('echo hi', user='root')),
|
||||
[('sudo', 'sh', '-euc', 'echo hi')]
|
||||
),
|
||||
(
|
||||
Ssh('host', Run('echo hi', user='root')),
|
||||
[('ssh', 'host', 'sudo', 'sh', '-euc', 'echo hi')]
|
||||
),
|
||||
(
|
||||
Buildah('alpine', Run('echo hi')),
|
||||
[
|
||||
('buildah', 'from', 'alpine'),
|
||||
('buildah', 'mount', ''),
|
||||
('buildah', 'run', '', '--', 'sh', '-euc', 'echo hi'),
|
||||
('buildah', 'umount', ''),
|
||||
('buildah', 'rm', ''),
|
||||
]
|
||||
),
|
||||
(
|
||||
Buildah('alpine', Run('echo hi', user='root')),
|
||||
[
|
||||
('buildah', 'from', 'alpine'),
|
||||
('buildah', 'mount', ''),
|
||||
('buildah', 'run', '--user', 'root', '', '--', 'sh', '-euc', 'echo hi'),
|
||||
('buildah', 'umount', ''),
|
||||
('buildah', 'rm', ''),
|
||||
]
|
||||
),
|
||||
(
|
||||
Ssh('host', Buildah('alpine', Run('echo hi', user='root'))),
|
||||
[
|
||||
('ssh', 'host', 'buildah', 'from', 'alpine'),
|
||||
('ssh', 'host', 'buildah', 'mount', ''),
|
||||
('ssh', 'host', 'buildah', 'run', '--user', 'root', '', '--', 'sh', '-euc', 'echo hi'),
|
||||
('ssh', 'host', 'buildah', 'umount', ''),
|
||||
('ssh', 'host', 'buildah', 'rm', ''),
|
||||
]
|
||||
),
|
||||
]
|
||||
@pytest.mark.parametrize(
|
||||
'script,commands',
|
||||
test_args_params
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_args(script, commands):
|
||||
with Proc.mock():
|
||||
await script()
|
||||
assert commands == Proc.test
|
||||
@@ -0,0 +1,101 @@
|
||||
import pytest
|
||||
|
||||
from shlax.targets.stub import Stub
|
||||
from shlax.actions.run import Run
|
||||
from shlax.actions.parallel import Parallel
|
||||
from shlax.result import Result
|
||||
|
||||
|
||||
class Error:
|
||||
async def __call__(self, target):
|
||||
raise Exception('lol')
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_success():
|
||||
action = Run('echo hi')
|
||||
target = Stub(action)
|
||||
await target()
|
||||
assert target.results[0].action == action
|
||||
assert target.results[0].status == 'success'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_error():
|
||||
action = Error()
|
||||
target = Stub(action)
|
||||
await target()
|
||||
assert target.results[0].action == action
|
||||
assert target.results[0].status == 'failure'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_nested():
|
||||
nested = Error()
|
||||
|
||||
class Nesting:
|
||||
async def __call__(self, target):
|
||||
await target(nested)
|
||||
nesting = Nesting()
|
||||
|
||||
target = Stub(nesting)
|
||||
await target()
|
||||
|
||||
assert len(target.results) == 2
|
||||
assert target.results[0].status == 'failure'
|
||||
assert target.results[0].action == nested
|
||||
assert target.results[1].status == 'failure'
|
||||
assert target.results[1].action == nesting
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_parallel():
|
||||
winner = Run('echo hi')
|
||||
looser = Error()
|
||||
parallel = Parallel(winner, looser)
|
||||
|
||||
target = Stub(parallel)
|
||||
await target()
|
||||
assert len(target.results) == 3
|
||||
assert target.results[0].status == 'success'
|
||||
assert target.results[0].action == winner
|
||||
assert target.results[1].status == 'failure'
|
||||
assert target.results[1].action == looser
|
||||
assert target.results[2].status == 'failure'
|
||||
assert target.results[2].action == parallel
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_function():
|
||||
async def hello(target):
|
||||
target.exec('hello')
|
||||
await Stub()(hello)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_method():
|
||||
class Example:
|
||||
def __init__(self):
|
||||
self.was_called = False
|
||||
async def test(self, target):
|
||||
self.was_called = True
|
||||
|
||||
example = Example()
|
||||
action = example.test
|
||||
target = Stub()
|
||||
await target(action)
|
||||
assert example.was_called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_target_action():
|
||||
child = Stub(Run('echo hi'))
|
||||
parent = Stub(child)
|
||||
|
||||
grandpa = Stub()
|
||||
await grandpa(parent)
|
||||
assert len(grandpa.results) == 3
|
||||
|
||||
grandpa = Stub(parent)
|
||||
await grandpa()
|
||||
assert len(grandpa.results) == 3
|
||||
Reference in New Issue
Block a user