Skip to content

Commit

Permalink
feat: add support for configuring Python logging #82
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcarneiro committed Mar 11, 2023
1 parent c52736b commit 1036444
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
40 changes: 20 additions & 20 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_mergedicts_lists():


def test_simple_config1():
jobs, web_config, _ = config.parse_config_string(
conf = config.parse_config_string(
"""
defaults:
shell: /bin/bash
Expand All @@ -51,9 +51,9 @@ def test_simple_config1():
""",
"",
)
assert web_config is None
assert len(jobs) == 1
job = jobs[0]
assert conf.web_config is None
assert len(conf.jobs) == 1
job = conf.jobs[0]
assert job.name == "test-03"
assert job.command == (
"trap \"echo '(ignoring SIGTERM)'\" TERM\n"
Expand All @@ -69,7 +69,7 @@ def test_simple_config1():


def test_config_default_report():
jobs, _, _ = config.parse_config_string(
conf = config.parse_config_string(
"""
defaults:
onFailure:
Expand All @@ -89,8 +89,8 @@ def test_config_default_report():
""",
"",
)
assert len(jobs) == 1
job = jobs[0]
assert len(conf.jobs) == 1
job = conf.jobs[0]
assert job.onFailure == (
{
"report": {
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_config_default_report():
def test_config_default_report_override():
# even if the default says send email on error, it should be possible for
# specific jobs to override the default and disable sending email.
jobs, _, _ = config.parse_config_string(
conf = config.parse_config_string(
"""
defaults:
onFailure:
Expand All @@ -163,8 +163,8 @@ def test_config_default_report_override():
""",
"",
)
assert len(jobs) == 1
job = jobs[0]
assert len(conf.jobs) == 1
job = conf.jobs[0]
assert job.onFailure == (
{
"report": {
Expand Down Expand Up @@ -210,13 +210,13 @@ def test_config_default_report_override():


def test_empty_config1():
jobs, web_config, _ = config.parse_config_string("", "")
assert len(jobs) == 0
assert web_config is None
conf = config.parse_config_string("", "")
assert len(conf.jobs) == 0
assert conf.web_config is None


def test_environ_file():
jobs, _, _ = config.parse_config_string(
conf = config.parse_config_string(
"""
defaults:
shell: /bin/bash
Expand All @@ -239,7 +239,7 @@ def test_environ_file():
""",
"",
)
job = jobs[0]
job = conf.jobs[0]

# NOTE: the file format implicitly verifies that the parsing is being
# done correctly on these fronts:
Expand All @@ -263,7 +263,7 @@ def test_environ_file():
def test_invalid_environ_file():
# invalid file (no key-value)
with pytest.raises(ConfigError) as exc:
jobs, _, _ = config.parse_config_string(
config.parse_config_string(
"""
defaults:
shell: /bin/bash
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_invalid_environ_file():

# non-existent file should raise ConfigError, not OSError
with pytest.raises(ConfigError) as exc:
jobs, _, _ = config.parse_config_string(
config.parse_config_string(
"""
defaults:
shell: /bin/bash
Expand Down Expand Up @@ -319,11 +319,11 @@ def test_invalid_environ_file():


def test_config_include():
jobs, _ = config.parse_config(
conf = config.parse_config(
os.path.join(os.path.dirname(__file__), "test_include_parent.yaml")
)
assert len(jobs) == 2
job1, job2 = jobs
assert len(conf.jobs) == 2
job1, job2 = conf.jobs
assert job1.name == "common-task"
assert job2.name == "test-03"
assert job1.shell == "/bin/ksh"
Expand Down
44 changes: 22 additions & 22 deletions tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def test_stream_reader(
"cronjob-1", "stderr", fake_stream, "", save_limit
)

config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -52,7 +52,7 @@ async def test_stream_reader(
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)

async def producer(fake_stream):
Expand All @@ -76,7 +76,7 @@ async def test_stream_reader_long_line():
"cronjob-1", "stderr", fake_stream, "", 500
)

config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -86,7 +86,7 @@ async def test_stream_reader_long_line():
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)

async def producer(fake_stream):
Expand Down Expand Up @@ -173,8 +173,8 @@ async def producer(fake_stream):
)
@pytest.mark.asyncio
async def test_report_mail(success, stdout, stderr, subject, body):
config, _, _ = yacron.config.parse_config_string(A_JOB, "")
job_config = config[0]
conf = yacron.config.parse_config_string(A_JOB, "")
job_config = conf.jobs[0]
print(job_config.onSuccess["report"])
job = Mock(
config=job_config,
Expand Down Expand Up @@ -314,8 +314,8 @@ async def test_report_sentry(
tmpdir,
monkeypatch,
):
config, _, _ = yacron.config.parse_config_string(A_JOB, "")
job_config = config[0]
conf = yacron.config.parse_config_string(A_JOB, "")
job_config = conf.jobs[0]

p = tmpdir.join("sentry-secret-dsn")
p.write("http://xxx:yyy@sentry/2")
Expand Down Expand Up @@ -435,7 +435,7 @@ async def test_report_shell(command, expected_output):
with tempfile.TemporaryDirectory() as tmp:
out_file_path = os.path.join(tmp, "unit_test_file")

config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
f"""
jobs:
- name: test
Expand All @@ -451,7 +451,7 @@ async def test_report_shell(command, expected_output):
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]

job = Mock(
config=job_config,
Expand Down Expand Up @@ -531,7 +531,7 @@ async def create_subprocess_exec(*args, **kwargs):
else:
command_snippet = " command: " + command

config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -548,7 +548,7 @@ async def create_subprocess_exec(*args, **kwargs):
),
"",
)
job_config = config[0]
job_config = conf.jobs[0]

job = yacron.job.RunningJob(job_config, None)

Expand All @@ -573,7 +573,7 @@ async def create_subprocess_exec(*args, **kwargs):

@pytest.mark.asyncio
async def test_execution_timeout():
config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -588,7 +588,7 @@ async def test_execution_timeout():
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)
await job.start()
await job.wait()
Expand All @@ -597,7 +597,7 @@ async def test_execution_timeout():

@pytest.mark.asyncio
async def test_error1():
config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -606,7 +606,7 @@ async def test_error1():
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)

await job.start()
Expand All @@ -617,7 +617,7 @@ async def test_error1():

@pytest.mark.asyncio
async def test_error2():
config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -626,7 +626,7 @@ async def test_error2():
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)

with pytest.raises(RuntimeError):
Expand All @@ -635,7 +635,7 @@ async def test_error2():

@pytest.mark.asyncio
async def test_error3():
config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -644,7 +644,7 @@ async def test_error3():
""",
"",
)
job_config = config[0]
job_config = conf.jobs[0]
job = yacron.job.RunningJob(job_config, None)

with pytest.raises(RuntimeError):
Expand Down Expand Up @@ -678,7 +678,7 @@ def connection_lost(*_):
host, port = transport.get_extra_info("sockname")
print("Listening UDP on %s:%s" % (host, port))

config, _, _ = yacron.config.parse_config_string(
conf = yacron.config.parse_config_string(
"""
jobs:
- name: test
Expand All @@ -693,7 +693,7 @@ def connection_lost(*_):
),
"",
)
job_config = config[0]
job_config = conf.jobs[0]

job = yacron.job.RunningJob(job_config, None)

Expand Down

0 comments on commit 1036444

Please sign in to comment.