Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ omit =
*/faust/tables/recovery.py

# not needed
*/faust/utils/functional.py
*/faust/utils/iso8601.py
*/faust/utils/platforms.py
*/faust/utils/tracing.py
*/faust/types/*
*/faust/__main__.py
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/utils/test_agent_stopper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from unittest.mock import Mock

import pytest

from faust.utils.agent_stopper import agent_stopper


@pytest.mark.asyncio
async def test_agent_stopper_crashes_app():
app = Mock(name="app")
await agent_stopper(app)
# It must force a non-zero exit by crashing the app with a RuntimeError.
app._crash.assert_called_once_with(RuntimeError)
16 changes: 15 additions & 1 deletion tests/unit/utils/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from faust.utils.functional import consecutive_numbers
from faust.utils.functional import consecutive_numbers, translate


@pytest.mark.parametrize(
Expand All @@ -14,3 +14,17 @@
)
def test_consecutive_numbers(numbers, expected):
assert next(consecutive_numbers(numbers), None) == expected


@pytest.mark.parametrize(
"table,s,expected",
[
({".": "_", "@": "."}, "foo.bar@baz", "foo_bar.baz"),
({".": "_"}, "foo.bar", "foo_bar"),
# multi-character patterns/replacements, not just single chars
({"foo": "bar"}, "foofoo", "barbar"),
({}, "unchanged", "unchanged"),
],
)
def test_translate(table, s, expected):
assert translate(table, s) == expected
35 changes: 35 additions & 0 deletions tests/unit/utils/test_platforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import builtins
import resource
from unittest.mock import patch

from faust.utils.platforms import max_open_files


@patch("resource.getrlimit", return_value=(1024, 4096))
def test_max_open_files__returns_hard_limit(getrlimit):
assert max_open_files() == 4096


@patch("platform.system", return_value="Linux")
@patch("resource.getrlimit", return_value=(1024, resource.RLIM_INFINITY))
def test_max_open_files__infinity_non_darwin(getrlimit, system):
assert max_open_files() is None


@patch("subprocess.check_output", return_value=b"kern.maxfilesperproc: 24576")
@patch("platform.system", return_value="Darwin")
@patch("resource.getrlimit", return_value=(1024, resource.RLIM_INFINITY))
def test_max_open_files__infinity_darwin_uses_sysctl(getrlimit, system, check_output):
assert max_open_files() == 24576


def test_max_open_files__no_resource_module():
real_import = builtins.__import__

def fake_import(name, *args, **kwargs):
if name == "resource":
raise ImportError("no resource module")
return real_import(name, *args, **kwargs)

with patch("builtins.__import__", side_effect=fake_import):
assert max_open_files() is None
Loading