-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class ParsingError(Exception): | ||
pass | ||
|
||
|
||
def pv_name_from_path(path): | ||
"""Given a path to a PB file relative to storage root, infer what the | ||
PV name is. | ||
In the AA storage, a PV name is broken up into parts | ||
and there are subdirectories with each part of the name. | ||
This method is to reverse that process so you can work out | ||
what a PV name is from the path to a PB file. | ||
The first three slashes in the path become dashes in the | ||
PV name. Subsequent slashes become colons. | ||
E.g. "BL14I/MO/STAGE/01/XF.RBV:2019.pb" goes to | ||
"BL14I-MO-STAGE-01:XF.RBV" | ||
""" | ||
#pattern = re.compile(r"((?:(?:[\w/]+)+)(?:.\w+)?):(\w+\.pb)") | ||
# Strip relative specifier from beginning | ||
if path[0] == ".": | ||
path = path[2:] | ||
|
||
split_by_dot = path.split(".") | ||
# There will be one dot if PV does not specify a field | ||
# otherwise two | ||
if len(split_by_dot) not in [2,3] or split_by_dot[-1] != "pb": | ||
raise ParsingError("Does not look like a protobuf file") | ||
|
||
# Strip off the trailing part of the file name | ||
# e.g. year | ||
before_colon = path.split(":")[0] | ||
path_as_list = before_colon.split("/") | ||
|
||
# Check that PV name matches convention in that it has at least 4 parts: | ||
# AA-BB-CC-DD[:EE:FF...] | ||
if len(path_as_list) < 4: | ||
raise ParsingError("Path too short") | ||
|
||
# The first four parts are joined by dashes | ||
pv_stem = "-".join(path_as_list[0:4]) | ||
|
||
# Subsequent parts are joined by colons | ||
if len(path_as_list) > 4: | ||
pv_name = ":".join([pv_stem] + path_as_list[4:]) | ||
else: | ||
pv_name = pv_stem | ||
|
||
return pv_name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
filterwarnings = | ||
ignore::DeprecationWarning | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ protobuf | |
pytz | ||
requests | ||
tzlocal | ||
click | ||
# Development | ||
pluggy>=0.12.0 | ||
pytest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ | |
'protobuf', | ||
'pytz', | ||
'requests', | ||
'tzlocal' | ||
'tzlocal', | ||
] | ||
) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from aa import storage | ||
|
||
@pytest.mark.parametrize("path, pv", [ | ||
("BL13J/MO/PI/01/X:2018.pb", "BL13J-MO-PI-01:X"), | ||
("BL14I/VA/IONP/14/SP1OFF:2015.pb", "BL14I-VA-IONP-14:SP1OFF"), | ||
("BL14I/MO/STAGE/01/ROT/FERROR:2017.pb", "BL14I-MO-STAGE-01:ROT:FERROR"), | ||
("BL14I/MO/STAGE/01/XF.RBV:2019.pb", "BL14I-MO-STAGE-01:XF.RBV") | ||
]) | ||
def test_pv_name_from_path(path, pv): | ||
assert storage.pv_name_from_path(path) == pv | ||
|
||
@pytest.mark.parametrize("path,", [ | ||
("BL13J/MO/PI:2018.pb"), | ||
("BL13J:2018.pb"), | ||
("BL14I/MO/STAGE/01/XF.RBV"), | ||
]) | ||
def test_pv_name_from_path_raises_ParsingError_if_not_conventional(path): | ||
with pytest.raises(storage.ParsingError): | ||
storage.pv_name_from_path(path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
|
||
[tox] | ||
envlist = py27, py35, py36, py37 | ||
envlist = py27, py35, py36, py37, py38 | ||
toxworkdir = {env:TOXDIR:.tox}/aapy | ||
|
||
[testenv] | ||
deps = -rrequirements.txt | ||
passenv = TRAVIS TRAVIS_* | ||
commands = | ||
# run tests in test directory and get coverage on aa package | ||
python -m pytest --cov=aa test | ||
python -m pytest -vv --cov=aa test | ||
# run pylint only on aa package | ||
python -m pytest --pylint --pylint-error-types=WEF aa # run pylint | ||
|