From d34ad7efc98adea7c0b515a70a08bdfe70232e85 Mon Sep 17 00:00:00 2001 From: Pedro Brochado Date: Mon, 4 Dec 2023 12:56:24 -0300 Subject: [PATCH] fixup! Refactor `parse_modular`, docstrings and small type annotations --- pulp_rpm/tests/unit/modulemd.yaml | 317 --------------------------- pulp_rpm/tests/unit/test_modulemd.py | 65 +++++- 2 files changed, 58 insertions(+), 324 deletions(-) delete mode 100644 pulp_rpm/tests/unit/modulemd.yaml diff --git a/pulp_rpm/tests/unit/modulemd.yaml b/pulp_rpm/tests/unit/modulemd.yaml deleted file mode 100644 index b56f6663d..000000000 --- a/pulp_rpm/tests/unit/modulemd.yaml +++ /dev/null @@ -1,317 +0,0 @@ ---- -document: modulemd -version: 2 -data: - name: kangaroo - stream: 1.10 - version: 20180730223407 - context: deadbeef - arch: noarch - summary: Kangaroo 0.3 module - description: >- - A module for the kangaroo 0.3 package - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - kangaroo - artifacts: - rpms: - - kangaroo-0:0.3-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: kangaroo - stream: "1.10" - version: 20180704111719 - context: deadbeef - arch: noarch - summary: Kangaroo 0.2 module - description: >- - A module for the kangaroo 0.2 package - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - kangaroo - artifacts: - rpms: - - kangaroo-0:0.2-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 0 - version: 201809302113907 - context: deadbeef - arch: noarch - summary: Duck 0.8 module - description: >- - A module for the duck 0.8 package - license: - module: - - MIT - content: - - MIT - dependencies: - - buildrequires: - walrus: [0.71, 5.21] - platform: [f28] - requires: - walrus: [0.71, 5.21] - platform: [f28] - - buildrequires: - platform: [el8] - requires: - platform: [el8] - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.8-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 0 - version: 20180730233102 - context: deadbeef - arch: noarch - summary: Duck 0.7 module - description: >- - A module for the duck 0.7 package - license: - module: - - MIT - content: - - MIT - dependencies: - - buildrequires: - walrus: [] - platform: [-f29, -f30] - requires: - walrus: [] - platform: [-f29, -f30] - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.7-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 0 - version: 20180704244205 - context: deadbeef - arch: noarch - summary: Duck 0.6 module - description: >- - A module for the duck 0.6 package - license: - module: - - MIT - content: - - MIT - dependencies: - - buildrequires: - walrus: [-5.21] - platform: [f28] - requires: - walrus: [-5.21] - platform: [f28] - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.6-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 4 - version: 20190619105003 - context: deadbeef - arch: noarch - summary: duck:4 stream - description: >- - A module stream for the duck 0.8 package - with a profile name of 'daffy' - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.8-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 5 - version: 20190621095605 - context: deadbeef - arch: noarch - summary: duck:5 stream - description: >- - A module stream for the duck 0.8 package - with a profile name of 'daffy'. - Ensures different streams with similar - RPM artifacts are not libsolv'd on copy. - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.8-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: duck - stream: 6 - version: 20190621095706 - context: deadbeef - arch: noarch - summary: duck:6 stream - description: >- - A module stream for the duck 0.8 and frog 0.1 package - with a profile name of 'taffy'. - Ensures different streams with similar RPM artifacts are not - libsolv'd on copy. - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - duck - artifacts: - rpms: - - duck-0:0.8-1.noarch - - frog-0:0.1-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: walrus - stream: 5.21 - version: 20180704144203 - context: deadbeef - arch: x86_64 - summary: Walrus 5.21 module - description: >- - A module for the walrus 5.21 package - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - walrus - artifacts: - rpms: - - walrus-0:5.21-1.noarch -... ---- -document: modulemd -version: 2 -data: - name: walrus - stream: 0.71 - version: 20180707144203 - context: c0ffee42 - arch: x86_64 - summary: Walrus 0.71 module - description: >- - A module for the walrus 0.71 package - license: - module: - - MIT - content: - - MIT - profiles: - default: - rpms: - - walrus - flipper: - rpms: - - walrus - artifacts: - rpms: - - walrus-0:0.71-1.noarch -... ---- -document: modulemd-defaults -version: 1 -data: - module: walrus - stream: 0.71 - profiles: - 5.21: [default] - 0.71: [flipper] -... ---- -document: modulemd-defaults -version: 1 -data: - module: duck - stream: 0 - profiles: - 0: [default] - 4: [daffy] - 5: [laffy] - 6: [taffy] -... ---- -document: modulemd-defaults -version: 1 -data: - module: kangaroo - stream: 0 - profiles: - 0: [default] -... diff --git a/pulp_rpm/tests/unit/test_modulemd.py b/pulp_rpm/tests/unit/test_modulemd.py index 17c3a6725..b89f30b2e 100644 --- a/pulp_rpm/tests/unit/test_modulemd.py +++ b/pulp_rpm/tests/unit/test_modulemd.py @@ -1,19 +1,70 @@ -from pathlib import Path +from pulp_rpm.app.modulemd import parse_modular import os -from pulp_rpm.app.modulemd import parse_modular +sample_file_data = """ +--- +document: modulemd +version: 2 +data: + name: kangaroo + stream: 1.10 + version: 20180730223407 + context: deadbeef + arch: noarch + summary: Kangaroo 0.3 module + description: >- + A module for the kangaroo 0.3 package + license: + module: + - MIT + content: + - MIT + profiles: + default: + rpms: + - kangaroo + artifacts: + rpms: + - kangaroo-0:0.3-1.noarch +... +--- +document: modulemd +version: 2 +data: + name: kangaroo + stream: "1.10" + version: 20180704111719 + context: deadbeef + arch: noarch + summary: Kangaroo 0.2 module + description: >- + A module for the kangaroo 0.2 package + license: + module: + - MIT + content: + - MIT + profiles: + default: + rpms: + - kangaroo + artifacts: + rpms: + - kangaroo-0:0.2-1.noarch +... +""" def test_parse_modular_preserves_literal_unquoted_values_3285(tmp_path): """Unquoted yaml numbers with trailing/leading zeros are preserved""" - # copy sample file to tmp_path, so it have proper test permissions + # write data to test_file os.chdir(tmp_path) - sample = Path("/src/pulp_rpm/pulp_rpm/tests/unit/modulemd.yaml") - test_file = Path("modulemd.yaml") - test_file.write_bytes(sample.read_bytes()) + file_name = "modulemd.yaml" + with open(file_name, "w") as file: + file.write(sample_file_data) - all, default, obsoletes = parse_modular(str(test_file.absolute())) + all, default, obsoletes = parse_modular(str(file_name)) # check the first two entries kangoroo1 = all[0] # unquoted