From 73449af92725a26440c302a221d2d617484d9abb Mon Sep 17 00:00:00 2001 From: Derek Hower Date: Wed, 11 Dec 2024 12:01:51 -0800 Subject: [PATCH] Get YAML resolve tests working --- Rakefile | 1 + arch/ext/Xmock.yaml | 156 +++++++++++++++++++++++++++++++++++ lib/test/test_yaml_loader.rb | 8 +- lib/yaml_resolver.py | 4 +- requirements.txt | 6 +- 5 files changed, 169 insertions(+), 6 deletions(-) create mode 100644 arch/ext/Xmock.yaml diff --git a/Rakefile b/Rakefile index 7aecde5b7..31460b853 100644 --- a/Rakefile +++ b/Rakefile @@ -105,6 +105,7 @@ desc "Clean up all generated files" task :clean do FileUtils.rm_rf $root / "gen" FileUtils.rm_rf $root / ".stamps" + FileUtils.rm_rf $root / ".home" end namespace :test do diff --git a/arch/ext/Xmock.yaml b/arch/ext/Xmock.yaml new file mode 100644 index 000000000..2c0a43d68 --- /dev/null +++ b/arch/ext/Xmock.yaml @@ -0,0 +1,156 @@ +# yaml-language-server: $schema=../../schemas/ext_schema.json + +$schema: "ext_schema.json#" +kind: extension +name: Xmock +type: privileged +long_name: Mock Extension (for testing database) +description: This is just for testing +versions: +- version: "0.9.9" + state: development +- version: "1.0.0" + state: ratified + ratification_date: 2024-04 +params: + MOCK_ENUM_2_INTS: + description: foo + schema: + type: integer + enum: [32, 64] + MOCK_ENUM_2_STRINGS: + description: foo + schema: + type: string + enum: ["low", "high"] + MOCK_BOOL_1: + description: foo + schema: + type: boolean + MOCK_BOOL_2: + description: foo + schema: + type: boolean + MOCK_32_BIT_INT: + description: foo + schema: + type: integer + minimum: 0 + maximum: 0xffffffff + MOCK_64_BIT_INT: + description: foo + schema: + type: integer + minimum: 0 + maximum: 0xffffffffffffffff + MOCK_1_BIT_INT: + description: foo + schema: + type: integer + minimum: 0 + maximum: 1 + MOCK_2_BIT_INT: + description: foo + schema: + type: integer + minimum: 0 + maximum: 3 + MOCK_25_BIT_INT: + description: foo + schema: + type: integer + minimum: 0 + maximum: 33554431 + MOCK_INT_RANGE_0_TO_2: + description: foo + schema: + type: integer + minimum: 0 + maximum: 2 + MOCK_INT_RANGE_0_TO_127: + description: foo + schema: + type: integer + minimum: 0 + maximum: 127 + MOCK_INT_RANGE_0_TO_999: + description: foo + schema: + type: integer + minimum: 0 + maximum: 999 + MOCK_INT_RANGE_0_TO_1023: + description: foo + schema: + type: integer + minimum: 0 + maximum: 1023 + MOCK_INT_RANGE_1000_TO_2048: + description: foo + schema: + type: integer + minimum: 1000 + maximum: 2048 + MOCK_INT_RANGE_0_TO_128: + description: foo + schema: + type: integer + minimum: 0 + maximum: 128 + MOCK_INT_RANGE_1_TO_128: + description: foo + schema: + type: integer + minimum: 1 + maximum: 128 + MOCK_ARRAY_INT_ENUM: + description: foo + schema: + type: array + items: + type: integer + enum: [0, 1] + minItems: 1 + maxItems: 2 + uniqueItems: true + MOCK_ARRAY_MIN_ONLY: + description: foo + schema: + type: array + items: + type: integer + enum: [0, 1] + minItems: 3 + MOCK_ARRAY_MAX_ONLY: + description: foo + schema: + type: array + items: + type: integer + enum: [0, 1] + maxItems: 10 + MOCK_ARRAY_STRING_ENUM1: + description: foo + schema: + type: array + items: + type: string + enum: [ABC, DEF, GHI] + MOCK_ARRAY_STRING_ENUM2: + description: foo + schema: + type: array + items: + type: string + enum: [ABC, DEF, GHI] + MOCK_ARRAY_BOOL_ARRAY_OF_8_FIRST_2_FALSE: + description: foo + schema: + type: array + items: + - const: false + - const: false + additionalItems: + type: boolean + maxItems: 8 + minItems: 8 diff --git a/lib/test/test_yaml_loader.rb b/lib/test/test_yaml_loader.rb index 66213f561..6206c4aa9 100644 --- a/lib/test/test_yaml_loader.rb +++ b/lib/test/test_yaml_loader.rb @@ -20,8 +20,9 @@ def resolve_yaml(yaml) File.write(test_dir / "test.yaml", yaml) stdout, stderr, status = - Open3.capture3("#{$root}/.home/.venv/bin/python3 #{$root}/lib/yaml_resolver.py resolve #{arch_dir} #{resolved_dir}") - + Dir.chdir($root) do + Open3.capture3("/bin/bash -c \"source #{$root}/.home/.venv/bin/activate && #{$root}/.home/.venv/bin/python3 #{$root}/lib/yaml_resolver.py resolve --no-progress #{arch_dir} #{resolved_dir}\"") + end # puts stdout # puts stderr # puts status @@ -47,7 +48,8 @@ def resolve_multi_yaml(*yamls) File.write(test_dir / "test#{i + 1}.yaml", yaml) end - `#{$root}/.home/.venv/bin/python3 #{$root}/lib/yaml_resolver.py resolve #{arch_dir} #{resolved_dir}` + system "/bin/bash -c \"source #{$root}/.home/.venv/bin/activate && #{$root}/.home/.venv/bin/python3 #{$root}/lib/yaml_resolver.py resolve #{arch_dir} #{resolved_dir}\"" + # `source #{$root}/.home/.venv/bin/activate && python3 #{$root}/lib/yaml_resolver.py resolve #{arch_dir} #{resolved_dir}` if $CHILD_STATUS == 0 YAML.load_file(resolved_dir / "test" / "test1.yaml") diff --git a/lib/yaml_resolver.py b/lib/yaml_resolver.py index b24d10dbd..4fe575297 100644 --- a/lib/yaml_resolver.py +++ b/lib/yaml_resolver.py @@ -434,6 +434,7 @@ def resolve_file(rel_path : str | Path, arch_dir: str | Path, resolved_dir: str all_parser = subparsers.add_parser('resolve', help='Resolve all architecture files') all_parser.add_argument("arch_dir", type=str, help="Unresolved architecture (input) directory") all_parser.add_argument("resolved_dir", type=str, help="Resolved architecture (output) directory") + all_parser.add_argument("--no-progress", action="store_true", help="Don't display progress bar") args = cmdparser.parse_args() @@ -460,7 +461,8 @@ def resolve_file(rel_path : str | Path, arch_dir: str | Path, resolved_dir: str resolved_paths = glob.glob(f"**/*.yaml", recursive=True, root_dir=args.resolved_dir) arch_paths.extend(resolved_paths) arch_paths = list(set(arch_paths)) - for arch_path in tqdm(arch_paths, ascii=True, desc="Resolving arch"): + iter = arch_paths if args.no_progress else tqdm(arch_paths, ascii=True, desc="Resolving arch") + for arch_path in iter: resolved_arch_path = f"{UDB_ROOT}/{args.resolved_dir}/{arch_path}" if not os.path.isabs(args.resolved_dir) else f"{args.resolved_dir}/{arch_path}" os.makedirs(os.path.dirname(resolved_arch_path), exist_ok=True) resolve_file(arch_path, args.arch_dir, args.resolved_dir) diff --git a/requirements.txt b/requirements.txt index 0878c6540..37293bfb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ pre_commit==4.0.1 -PyYAML==6.0.2 -jsonschema +jsonschema==4.23.0 +tqdm==4.67.1 +ruamel.yaml==0.18.6 +mergedeep==1.3.4