-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes several issues found by the new Grapher module work (#105)
* Addresses issue where variables that can't be rendered are 569XZilmssign escaped when get_value() is called with the sub_vars flag * Fixes pickling SentinelTypes and guards against bad dependency data * Adds integration test to detect pickling regressions * Fixes default initialization type in get_all_dependencies() * Adds SentinelType pickle integration test. * Implements @dholth's approach for the SentinelType
- Loading branch information
1 parent
30999ec
commit 26eab68
Showing
8 changed files
with
554 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
""" | ||
:Description: Integration tests for the RecipeParserConvert class | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import pickle | ||
from typing import Callable | ||
|
||
import pytest | ||
|
||
from conda_recipe_manager.parser.recipe_parser import RecipeParser | ||
from conda_recipe_manager.parser.recipe_parser_convert import RecipeParserConvert | ||
from conda_recipe_manager.parser.recipe_parser_deps import RecipeParserDeps | ||
from conda_recipe_manager.parser.selector_parser import SelectorParser | ||
from conda_recipe_manager.parser.types import SchemaVersion | ||
from conda_recipe_manager.types import SentinelType | ||
from tests.file_loading import TEST_FILES_PATH, load_file | ||
|
||
|
||
def test_pickle_integration_sentinel_type() -> None: | ||
""" | ||
Verifies that the `SentinelType` is pickle-able. All `SentinelType` instances act as a second `None`-type. | ||
""" | ||
assert pickle.loads(pickle.dumps(SentinelType())) == SentinelType() # type: ignore[misc] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file,constructor", | ||
[ | ||
("types-toml.yaml", RecipeParser), | ||
("cctools-ld64.yaml", RecipeParser), | ||
("v1_format/v1_types-toml.yaml", RecipeParser), | ||
("v1_format/v1_cctools-ld64.yaml", RecipeParser), | ||
("types-toml.yaml", RecipeParserConvert), | ||
("cctools-ld64.yaml", RecipeParserConvert), | ||
("v1_format/v1_types-toml.yaml", RecipeParserConvert), | ||
("v1_format/v1_cctools-ld64.yaml", RecipeParserConvert), | ||
("types-toml.yaml", RecipeParserDeps), | ||
("cctools-ld64.yaml", RecipeParserDeps), | ||
("v1_format/v1_types-toml.yaml", RecipeParserDeps), | ||
("v1_format/v1_cctools-ld64.yaml", RecipeParserDeps), | ||
], | ||
) | ||
def test_pickle_integration_recipe_parsers(file: str, constructor: Callable[[str], RecipeParser]) -> None: | ||
""" | ||
Verifies that recipe parsers can be round-tripped with `pickle`'s serialization system. This ensures RecipeParser | ||
classes can be used with standard libraries that utilize `pickle`, like `multiprocessing`. | ||
Prior to this test, `RecipeParser` classes could not be reliably pickled due to the original implementation of the | ||
`SentinelType`. This caused some data corruption issues when `RecipeParser` instances were being generated by | ||
the thread pool tooling available in `multiprocessing`. | ||
More details about this problem can be found in this PR: | ||
https://github.com/conda-incubator/conda-recipe-manager/pull/105 | ||
""" | ||
file_text = load_file(TEST_FILES_PATH / file) | ||
parser = constructor(file_text) | ||
assert pickle.loads(pickle.dumps(parser)).render() == parser.render() # type: ignore[misc] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"selector,schema", | ||
[ | ||
# TODO: Add V1 when V1 selectors are supported | ||
("[osx]", SchemaVersion.V0), | ||
("[osx and win-32]", SchemaVersion.V0), | ||
], | ||
) | ||
def test_pickle_integration_selector_parser(selector: str, schema: SchemaVersion) -> None: | ||
""" | ||
This test ensures that the SelectorParser class is `pickle`-able. | ||
""" | ||
parser = SelectorParser(selector, schema) | ||
assert str(pickle.loads(pickle.dumps(parser))) == str(parser) # type: ignore[misc] |
Oops, something went wrong.