Skip to content

Commit 56d34ff

Browse files
authored
fix: Fix schema related tests failed when WD is not project root (#2702)
1 parent 2c5d27e commit 56d34ff

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

samtranslator/schema/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
from pathlib import Path
34
from typing import Any, Dict, Optional, Union, TypeVar
45
from functools import partial
@@ -21,7 +22,8 @@
2122

2223
LenientBaseModel = pydantic.BaseModel
2324

24-
_DOCS = json.loads(Path("samtranslator", "schema", "docs.json").read_bytes())
25+
_thisdir = os.path.dirname(os.path.abspath(__file__))
26+
_DOCS = json.loads(Path(_thisdir, "docs.json").read_bytes())
2527

2628

2729
def get_prop(stem: str) -> Any:

tests/schema/test_validate_schema.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
from samtranslator.yaml_helper import yaml_parse
1414

15-
SCHEMA = json.loads(Path("samtranslator/schema/schema.json").read_bytes())
15+
PROJECT_ROOT = Path(__file__).parent.parent.parent
16+
17+
SCHEMA = json.loads(PROJECT_ROOT.joinpath("samtranslator/schema/schema.json").read_bytes())
1618

1719
# TODO: Enable (most likely) everything but 'error_*' and 'basic_schema_validation_failure'
1820
SKIPPED_TESTS = [
@@ -61,12 +63,12 @@ def should_skip_test(s: str) -> bool:
6163

6264
def get_all_test_templates():
6365
return (
64-
list(Path("tests/translator/input").glob("**/*.yaml"))
65-
+ list(Path("tests/translator/input").glob("**/*.yml"))
66-
+ list(Path("tests/validator/input").glob("**/*.yaml"))
67-
+ list(Path("tests/validator/input").glob("**/*.yml"))
68-
+ list(Path("integration/resources/templates").glob("**/*.yaml"))
69-
+ list(Path("integration/resources/templates").glob("**/*.yml"))
66+
list(Path(PROJECT_ROOT, "tests/translator/input").glob("**/*.yaml"))
67+
+ list(Path(PROJECT_ROOT, "tests/translator/input").glob("**/*.yml"))
68+
+ list(Path(PROJECT_ROOT, "tests/validator/input").glob("**/*.yaml"))
69+
+ list(Path(PROJECT_ROOT, "tests/validator/input").glob("**/*.yml"))
70+
+ list(Path(PROJECT_ROOT, "integration/resources/templates").glob("**/*.yaml"))
71+
+ list(Path(PROJECT_ROOT, "integration/resources/templates").glob("**/*.yml"))
7072
)
7173

7274

@@ -81,8 +83,8 @@ def test_validate_schema(self, testcase):
8183

8284
@parameterized.expand(
8385
[
84-
"tests/translator/input/error_schema_validation_wrong_property.yaml",
85-
"tests/translator/input/error_schema_validation_wrong_type.yaml",
86+
(PROJECT_ROOT.joinpath("tests/translator/input/error_schema_validation_wrong_property.yaml"),),
87+
(PROJECT_ROOT.joinpath("tests/translator/input/error_schema_validation_wrong_type.yaml"),),
8688
]
8789
)
8890
def test_validate_schema_error(self, testcase):

0 commit comments

Comments
 (0)