Skip to content

Commit

Permalink
Get YAML resolve tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Dec 11, 2024
1 parent a417f66 commit 73449af
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 6 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
156 changes: 156 additions & 0 deletions arch/ext/Xmock.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions lib/test/test_yaml_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion lib/yaml_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 73449af

Please sign in to comment.