stages,test: fix lint errors and add basic unit tests
Add very simple unit tests as a starting point for the new parsing functions in `util/parsing.py`.
This commit is contained in:
parent
6d4d1962eb
commit
249107a028
6 changed files with 47 additions and 12 deletions
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from typing import Dict, Union
|
||||||
from typing import Union, Dict
|
|
||||||
from urllib.parse import ParseResult, urlparse
|
from urllib.parse import ParseResult, urlparse
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,7 +35,7 @@ def parse_size(s: str) -> Union[int, str]:
|
||||||
raise TypeError(f"invalid size value: '{s}'")
|
raise TypeError(f"invalid size value: '{s}'")
|
||||||
|
|
||||||
|
|
||||||
def parse_mount(url: ParseResult, args: Dict):
|
def parse_mount(url: ParseResult, args: Dict) -> os.PathLike:
|
||||||
"""
|
"""
|
||||||
Parses the mount URL to extract the root path.
|
Parses the mount URL to extract the root path.
|
||||||
|
|
||||||
|
|
@ -55,7 +54,7 @@ def parse_mount(url: ParseResult, args: Dict):
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
def parse_input(url: ParseResult, args: Dict):
|
def parse_input(url: ParseResult, args: Dict) -> os.PathLike:
|
||||||
"""
|
"""
|
||||||
Parses the input URL to extract the root path.
|
Parses the input URL to extract the root path.
|
||||||
|
|
||||||
|
|
@ -71,7 +70,7 @@ def parse_input(url: ParseResult, args: Dict):
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
def parse_location(location, args):
|
def parse_location(location: str, args: Dict) -> str:
|
||||||
"""
|
"""
|
||||||
Parses the location URL to derive the corresponding file path.
|
Parses the location URL to derive the corresponding file path.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
@ -38,6 +37,7 @@ SCHEMA_2 = r"""
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def main(args, options):
|
def main(args, options):
|
||||||
for path, cmdargs in options["items"].items():
|
for path, cmdargs in options["items"].items():
|
||||||
immutable = cmdargs["immutable"]
|
immutable = cmdargs["immutable"]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import sys
|
import sys
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import osbuild.api
|
import osbuild.api
|
||||||
from osbuild.util import bls
|
from osbuild.util import bls, parsing
|
||||||
|
|
||||||
|
|
||||||
def main(args, options):
|
def main(args, options):
|
||||||
|
|
@ -15,6 +14,6 @@ def main(args, options):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
args = osbuild.api.arguments()
|
_args = osbuild.api.arguments()
|
||||||
r = main(args, args["options"])
|
r = main(_args, _args["options"])
|
||||||
sys.exit(r)
|
sys.exit(r)
|
||||||
|
|
|
||||||
|
|
@ -37,3 +37,41 @@ def test_parse_size():
|
||||||
else:
|
else:
|
||||||
res = parsing.parse_size(s)
|
res = parsing.parse_size(s)
|
||||||
assert res == num, f"{s} parsed as {res} (wanted {num})"
|
assert res == num, f"{s} parsed as {res} (wanted {num})"
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_location_mounts():
|
||||||
|
args = {
|
||||||
|
"paths": {
|
||||||
|
"mounts": "/run/osbuild/mounts",
|
||||||
|
},
|
||||||
|
"mounts": {
|
||||||
|
"root": {
|
||||||
|
"path": "/run/osbuild/mounts/.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
location = "mount://root/"
|
||||||
|
path = parsing.parse_location(location, args)
|
||||||
|
assert path == "/run/osbuild/mounts/."
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_location_tree():
|
||||||
|
args = {
|
||||||
|
"tree": "/run/osbuild/tree",
|
||||||
|
}
|
||||||
|
location = "tree:///disk.img"
|
||||||
|
path = parsing.parse_location(location, args)
|
||||||
|
assert path == "/run/osbuild/tree/disk.img"
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_location_inputs():
|
||||||
|
args = {
|
||||||
|
"inputs": {
|
||||||
|
"tree": {
|
||||||
|
"path": "/run/osbuild/inputs/tree",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
location = "input://tree/"
|
||||||
|
path = parsing.parse_location(location, args)
|
||||||
|
assert path == "/run/osbuild/inputs/tree/."
|
||||||
|
|
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -28,7 +28,7 @@ setenv =
|
||||||
LINTABLES_EXCLUDES = "*.json,*.sh"
|
LINTABLES_EXCLUDES = "*.json,*.sh"
|
||||||
LINTABLES_EXCLUDES_RE = ".*\.json$,.*\.sh"
|
LINTABLES_EXCLUDES_RE = ".*\.json$,.*\.sh"
|
||||||
TYPEABLES = osbuild
|
TYPEABLES = osbuild
|
||||||
TYPEABLES_STRICT = ./osbuild/main_cli.py
|
TYPEABLES_STRICT = ./osbuild/main_cli.py ./osbuild/util/parsing.py
|
||||||
|
|
||||||
passenv =
|
passenv =
|
||||||
TEST_CATEGORY
|
TEST_CATEGORY
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue