Skip to content

Commit

Permalink
Rewrite tests for base.command with 'ls'
Browse files Browse the repository at this point in the history
  • Loading branch information
uwefladrich committed Nov 28, 2023
1 parent d129e36 commit af3e537
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions tests/tasks/base/test_command.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
import os
import time

import yaml

import scriptengine.logging
from scriptengine.yaml.parser import parse


Expand All @@ -12,40 +12,35 @@ def from_yaml(string):


def test_command_ls(tmp_path, caplog):

os.chdir(tmp_path)
(tmp_path / "foo").touch()
time.sleep(2)

caplog.clear()
scriptengine.logging.configure(logging.INFO)
logger = logging.getLogger("se.task")
logger.propagate = True

from_yaml(
t = from_yaml(
"""
base.command:
name: ls
args: [ foo ]
"""
).run({})
assert ("se.task", logging.INFO, "foo") in caplog.record_tuples
)

with caplog.at_level(logging.INFO, logger="se.task"):
t.run({})
assert "foo" in [rec.message for rec in caplog.records]

def test_command_ls_not_exists(tmp_path, caplog):

os.chdir(tmp_path)

caplog.clear()
scriptengine.logging.configure(logging.INFO)
logger = logging.getLogger("se.task")
logger.propagate = True

from_yaml(
def test_command_ls_not_exists(tmp_path, caplog):
t = from_yaml(
"""
base.command:
name: ls
args: [ bar ]
args: [ foo ]
ignore_error: true
"""
).run({})
assert "Command returned error code " in caplog.text
)

with caplog.at_level(logging.WARN, logger="se.task"):
t.run({})
assert "Command returned error code 2" in [
rec.message for rec in caplog.records
]

0 comments on commit af3e537

Please sign in to comment.