Skip to content

Commit

Permalink
feat: change outPath to snake-case _out_path and add a setter method …
Browse files Browse the repository at this point in the history
…for it
  • Loading branch information
Renfu-Li committed Dec 21, 2023
1 parent a3f9a8b commit c5c6685
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/onc/modules/_OncArchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def getFile(self, filename: str = "", overwrite: bool = False):

if response.ok:
# Save file to output path
outPath: Path = self._config("outPath")
saveAsFile(response, outPath, filename, overwrite)
_out_path: Path = self._config("_out_path")
saveAsFile(response, _out_path, filename, overwrite)

else:
msg = _createErrorMessage(response)
Expand Down Expand Up @@ -110,8 +110,8 @@ def getDirectFiles(
downInfos = []
for filename in dataRows["files"]:
# only download if file doesn't exist (or overwrite is True)
outPath: Path = self._config("outPath")
filePath = outPath / filename
_out_path: Path = self._config("_out_path")
filePath = _out_path / filename
fileExists = os.path.exists(filePath)

if (not fileExists) or (fileExists and overwrite):
Expand Down
4 changes: 2 additions & 2 deletions src/onc/modules/_OncDelivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _downloadProductFiles(
status = dpf.download(
timeout,
self.pollPeriod,
self._config("outPath"),
self._config("_out_path"),
maxRetries,
overwrite,
)
Expand All @@ -196,7 +196,7 @@ def _downloadProductFiles(
status = dpf.download(
timeout,
self.pollPeriod,
self._config("outPath"),
self._config("_out_path"),
maxRetries,
overwrite,
)
Expand Down
11 changes: 7 additions & 4 deletions src/onc/onc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def __init__(
token,
production: bool = True,
showInfo: bool = False,
outPath: str | Path = "output",
_out_path: str | Path = "output",
timeout: int = 60,
):
self.token = re.sub(r"[^a-zA-Z0-9\-]+", "", token)
self.showInfo = showInfo
self.timeout = timeout
self.baseUrl = "https://data.oceannetworks.ca/"
self.outPath = Path(outPath)
self._out_path = Path(_out_path)

# switch to qa if needed
if not production:
Expand All @@ -42,18 +42,21 @@ def __init__(
self.realTime = _OncRealTime(self)
self.archive = _OncArchive(self)

def set_out_path(self, out_path: str | Path):
self._out_path = Path(out_path)

def print(self, obj, filename: str = ""):
"""
Helper for printing a JSON dictionary to the console or to a file
@filename: if present, creates a file with a ".json" extension
in "self.outPath" directory, and writes the output to the file.
in "self._out_path" directory, and writes the output to the file.
if not present, prints the output to the console.
"""
text = json.dumps(obj, indent=4)
if filename == "":
print(text)
else:
filePath = self.outPath / filename
filePath = self._out_path / filename
filePath = filePath.with_suffix(".json")

with open(filePath, "w+") as file:
Expand Down
6 changes: 3 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ pabot --testlevelsplit tests/robot/suites
_To run a single RF test suite (replace 0X with the prefix of the test file name, e.g., 01):_

```shell
robot tests/suites/01* # robot tests/suites/0X*
robot tests/robot/suites/01* # robot tests/robot/suites/0X*
```

_To run a single RF test in a test suite (replace Y with the prefix of the test name, e.g., 01):_

```shell
robot --test "01*" tests/suites/01* # robot --test "Y*" tests/suites/0X*
robot --test "01*" tests/robot/suites/01* # robot --test "Y*" tests/robot/suites/0X*
```

_To run pytest_
Expand All @@ -84,7 +84,7 @@ pytest
_`--variable TOKEN:${YOUR_TOKEN}` can be used if no `.env` file is present_

```shell
robot --variable TOKEN:${YOUR_TOKEN} tests/suites/01*
robot --variable TOKEN:${YOUR_TOKEN} tests/robot/suites/01*
```

Additionally, You can check the three bash files (testall, testcoverage and testsuite) for running the test suites.
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

@pytest.fixture
def requester(tmp_path) -> ONC:
return ONC(token, is_prod, outPath=tmp_path)
return ONC(token, is_prod, _out_path=tmp_path)
2 changes: 1 addition & 1 deletion tests/robot/libraries/delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def manualRunProduct(dpRequestId: int):

def manualDownloadProduct(dpRunId: int, outPath: str = "", resultsOnly: bool = False):
# Manually downloads runId
onc.outPath = Path(outPath)
onc.set_out_path(outPath)
return onc.downloadDataProduct(dpRunId, downloadResultsOnly=resultsOnly)


Expand Down

0 comments on commit c5c6685

Please sign in to comment.