-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from python-jsonschema/improve-file-handling
Improve file handling with lazy reads
- Loading branch information
Showing
8 changed files
with
167 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import platform | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from check_jsonschema.cli.main_command import build_checker | ||
from check_jsonschema.cli.main_command import main as cli_main | ||
|
||
|
||
@pytest.fixture | ||
def runner() -> CliRunner: | ||
return CliRunner(mix_stderr=False) | ||
|
||
|
||
@pytest.mark.skipif( | ||
platform.system() != "Linux", reason="test requires /proc/self/ mechanism" | ||
) | ||
def test_open_file_usage_never_exceeds_1000(runner, monkeypatch, tmp_path): | ||
schema_path = tmp_path / "schema.json" | ||
schema_path.write_text("{}") | ||
|
||
args = [ | ||
"--schemafile", | ||
str(schema_path), | ||
] | ||
|
||
for i in range(2000): | ||
instance_path = tmp_path / f"file{i}.json" | ||
instance_path.write_text("{}") | ||
args.append(str(instance_path)) | ||
|
||
checker = None | ||
|
||
def fake_execute(argv): | ||
nonlocal checker | ||
checker = build_checker(argv) | ||
|
||
monkeypatch.setattr("check_jsonschema.cli.main_command.execute", fake_execute) | ||
res = runner.invoke(cli_main, args) | ||
assert res.exit_code == 0, res.stderr | ||
|
||
assert checker is not None | ||
assert len(os.listdir("/proc/self/fd")) < 2000 | ||
for _fname, _data in checker._instance_loader.iter_files(): | ||
assert len(os.listdir("/proc/self/fd")), 2000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters