-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change from ValueError to a better formatted metaflow specific error for parsers * support Rye by skipping over non-requirement lines in lockfile * add unit tests for parsers. * fix yml parser regex for whitespaces
- Loading branch information
Showing
2 changed files
with
145 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from metaflow.plugins.pypi.parsers import ( | ||
requirements_txt_parser, | ||
conda_environment_yml_parser, | ||
pyproject_toml_parser, | ||
ParserValueError, | ||
) | ||
|
||
VALID_REQ = """ | ||
dummypkg==1.1.1 | ||
anotherpkg==0.0.1 | ||
""" | ||
|
||
INVALID_REQ = """ | ||
--no-index | ||
-e dummypkg==1.1.1 | ||
anotherpkg==0.0.1 | ||
""" | ||
|
||
VALID_RYE_LOCK = """ | ||
# generated by rye | ||
# use `rye lock` or `rye sync` to update this lockfile | ||
# | ||
# last locked with the following flags: | ||
# pre: false | ||
# features: [] | ||
# all-features: false | ||
# with-sources: false | ||
# generate-hashes: false | ||
# universal: false | ||
-e file:. | ||
dummypkg==1.1.1 | ||
# via some-dependency | ||
anotherpkg==0.0.1 | ||
# another-dependency | ||
""" | ||
|
||
VALID_TOML = """ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
[project] | ||
name = "test-package" | ||
version = "2020.0.0" | ||
dependencies = [ | ||
"dummypkg==1.1.1", | ||
"anotherpkg==0.0.1", | ||
] | ||
requires-python = ">=3.8" | ||
authors = [ | ||
{name = "Tester", email = "[email protected]"}, | ||
] | ||
maintainers = [ | ||
{name = "Tester", email = "[email protected]"} | ||
] | ||
description = "A lengthy project description" | ||
readme = "README.rst" | ||
license = "MIT" | ||
license-files = ["LICEN[CS]E.*"] | ||
keywords = ["parser", "testing"] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python" | ||
] | ||
[project.urls] | ||
Homepage = "https://example.com" | ||
""" | ||
|
||
# Keep the whitespace to make sure that loosely written yml is also handled. | ||
VALID_YML = """ | ||
dependencies: | ||
- dummypkg = 1.1.1 | ||
- anotherpkg=0.0.1 | ||
- python = 3.10.* | ||
""" | ||
|
||
|
||
def test_yml_parser(): | ||
result = conda_environment_yml_parser(VALID_YML) | ||
|
||
assert result["python"] == "3.10.*" | ||
assert result["packages"]["dummypkg"] == "1.1.1" | ||
assert result["packages"]["anotherpkg"] == "0.0.1" | ||
|
||
|
||
def test_requirements_parser(): | ||
# success case | ||
result = requirements_txt_parser(VALID_REQ) | ||
|
||
assert result["python"] == None | ||
assert result["packages"]["dummypkg"] == "1.1.1" | ||
assert result["packages"]["anotherpkg"] == "0.0.1" | ||
|
||
# Rye lockfile success case | ||
result = requirements_txt_parser(VALID_RYE_LOCK) | ||
|
||
assert result["python"] == None | ||
assert result["packages"]["dummypkg"] == "1.1.1" | ||
assert result["packages"]["anotherpkg"] == "0.0.1" | ||
|
||
# failures | ||
try: | ||
requirements_txt_parser(INVALID_REQ) | ||
raise Exception("parsing invalid content did not raise an expected exception.") | ||
except ParserValueError: | ||
pass # expected to raise | ||
|
||
|
||
def test_toml_parser(): | ||
result = pyproject_toml_parser(VALID_TOML) | ||
|
||
assert result["python"] == ">=3.8" | ||
assert result["packages"]["dummypkg"] == "1.1.1" | ||
assert result["packages"]["anotherpkg"] == "0.0.1" |