Commit 4670a882 authored by Matias Guijarro's avatar Matias Guijarro

mapping refactoring: beamline -> session

parent 4c728ea2
......@@ -154,11 +154,11 @@ class Log:
bliss logging utils
"""
def __init__(self, map_beamline):
self.map_beamline = map_beamline
map_beamline.add_map_handler(map_update_loggers)
def __init__(self, map):
self.map = map
self.map.add_map_handler(map_update_loggers)
logging.getLogger("session").setLevel(logging.WARNING) # setting starting level
map_beamline.trigger_update()
self.map.trigger_update()
def _check_log_level(self: (str, int), level):
"""
......@@ -219,9 +219,9 @@ class Log:
uselevel = self._check_log_level(level)
findlog = {
self.map_beamline.G.node[node]["_logger"].name
for node in self.map_beamline.G.node
if self.map_beamline.G.node[node]["_logger"].name
self.map.G.node[node]["_logger"].name
for node in self.map.G.node
if self.map.G.node[node]["_logger"].name
}
registered_loggers = [logging.getLogger(obj) for obj in findlog]
filtered_loggers = [
......@@ -471,14 +471,14 @@ def create_logger_name(G, node_id):
try:
# search before through devices
path = nx.shortest_path(G, "devices", node_id)
return "beamline." + ".".join(
return "session." + ".".join(
format_node(G, n, format_string="tag->name->__class__") for n in path
)
except (nx.exception.NetworkXNoPath, nx.exception.NodeNotFound):
pass
try:
# search next starting from beamline
path = nx.shortest_path(G, "beamline", node_id)
path = nx.shortest_path(G, "session", node_id)
return ".".join(
format_node(G, n, format_string="tag->name->__class__") for n in path
)
......@@ -490,7 +490,7 @@ def create_logger_name(G, node_id):
def map_update_loggers(G):
"""
Function to be called after map update (add to map_beamline handlers)
Function to be called after map update (add to map handlers)
Args:
G: networkX DiGraph (given by mapping module)
......
......@@ -283,7 +283,7 @@ class Map:
Remaps nodes with missing parents to 'devices'
"""
for node in list(self.G):
if node != "beamline" and not len(list(self.G.predecessors(node))):
if node != "session" and not len(list(self.G.predecessors(node))):
self.G.add_edge("devices", node)
logger.debug(f"Added parent to {node}")
......
......@@ -384,7 +384,7 @@ class Session(object):
self.__map.register("axes", parents_list=[self], tag="axes")
self.__map.register("counters", parents_list=[self], tag="counters")
self.__log = Log(map_beamline=self.__map)
self.__log = Log(map=self.__map)
self._load_config(env_dict, verbose)
......
......@@ -16,30 +16,28 @@ import bliss
@pytest.fixture
def beamline():
def map():
"""
Creates a new graph
"""
map = Map()
map.register("beamline")
map.register("devices", parents_list=["beamline"])
map.register("sessions", parents_list=["beamline"])
map.register("comms", parents_list=["beamline"])
map.register("counters", parents_list=["beamline"])
map.register("session")
map.register("devices", parents_list=["session"])
map.register("sessions", parents_list=["session"])
map.register("comms", parents_list=["session"])
map.register("counters", parents_list=["session"])
return map
@pytest.fixture
def params(beacon, beamline):
def params(beacon, map):
"""
Creates a new beacon and log instance
"""
logging.basicConfig(level=logging.WARNING)
log = Log(map_beamline=beamline)
log.map_beamline.add_map_handler(map_update_loggers)
log.map_beamline.trigger_update()
log = Log(map=map)
return beacon, log
......@@ -74,14 +72,7 @@ class MappedController(NotMappedController, LogMixin):
def test_bare_system(params):
all_loggers = logging.getLogger().manager.loggerDict
names = [
"beamline",
"beamline.devices",
"beamline.devices",
"beamline.counters",
"beamline.sessions",
"beamline.comms",
]
names = ["session", "session.devices", "session.counters", "session.comms"]
for name in names:
assert name in all_loggers.keys()
......@@ -94,13 +85,12 @@ def test_add_motor_m0(params):
all_loggers = logging.getLogger().manager.loggerDict
regex_list = [
r"beamline",
r"beamline\.devices",
r"beamline\.sessions",
r"beamline\.comms",
r"beamline\.counters",
r"beamline\.devices\.\w",
r"beamline\.devices\.default\.axes\.m0",
r"session",
r"session\.devices",
r"session\.comms",
r"session\.counters",
r"session\.devices\.\w",
r"session\.devices\.default\.axes\.m0",
]
for regex in regex_list:
......
......@@ -29,11 +29,11 @@ def beamline():
"""
map = Map()
map.register("beamline")
map.register("devices", parents_list=["beamline"])
map.register("sessions", parents_list=["beamline"])
map.register("comms", parents_list=["beamline"])
map.register("counters", parents_list=["beamline"])
map.register("session")
map.register("devices", parents_list=["session"])
map.register("sessions", parents_list=["session"])
map.register("comms", parents_list=["session"])
map.register("counters", parents_list=["session"])
return map
......@@ -68,7 +68,7 @@ def test_starting_map_length(beamline):
def test_path_to_non_existing_node(beamline):
with pytest.raises(nx.exception.NodeNotFound):
beamline.shortest_path("beamline", "non_existing_node")
beamline.shortest_path("session", "non_existing_node")
def test_path_to_with_non_existing_path(beamline):
......@@ -77,9 +77,9 @@ def test_path_to_with_non_existing_path(beamline):
def test_find_children(beamline):
children = beamline.find_children("beamline")
children = beamline.find_children("session")
assert isinstance(children, list)
assert len(list(beamline.find_children("beamline"))) == 4
assert len(list(beamline.find_children("session"))) == 4
def test_find_predecessor(beamline):
......@@ -87,14 +87,14 @@ def test_find_predecessor(beamline):
assert isinstance(predecessors, list)
_pre = list(predecessors)
assert len(_pre) == 1
assert _pre.pop() == "beamline"
assert _pre.pop() == "session"
def test_find_shortest_path(beamline):
"""this should be: beamline -> devices -> MotorControllerForM0 -> motor0"""
beamline.register("motor0", parents_list=["MotorControllerForM0"])
beamline.register("MotorControllerForM0")
path = beamline.shortest_path("beamline", "motor0")
path = beamline.shortest_path("session", "motor0")
assert isinstance(path, list)
assert len(path) == 4
......@@ -113,7 +113,7 @@ def test_find_shortest_path_reverse_order(beamline):
"""
beamline.register("MotorControllerForM0")
beamline.register("motor0", parents_list=["MotorControllerForM0"])
path = beamline.shortest_path("beamline", "motor0")
path = beamline.shortest_path("session", "motor0")
assert isinstance(path, list)
assert len(path) == 4
......@@ -125,10 +125,10 @@ def test_find_shortest_path_parallel(beamline):
"""
beamline.register("motor0")
beamline.register("MotorControllerForM0")
path = beamline.shortest_path("beamline", "motor0")
path = beamline.shortest_path("session", "motor0")
assert isinstance(path, list)
assert len(path) == 3
path = beamline.shortest_path("beamline", "MotorControllerForM0")
path = beamline.shortest_path("session", "MotorControllerForM0")
assert isinstance(path, list)
assert len(path) == 3
......@@ -142,7 +142,7 @@ def test_remap_children(beamline):
"""
beamline.register("motor0")
beamline.register("MotorControllerForM0", children_list=["motor0"])
path = beamline.shortest_path("beamline", "motor0")
path = beamline.shortest_path("session", "motor0")
assert len(path) == 4
......@@ -173,7 +173,7 @@ def test_complex_map_remove_children(complex_beamline):
complex_beamline.delete(id_="devices")
_pre = list(complex_beamline.find_predecessors("Contr_1"))
assert len(_pre) == 1
assert _pre.pop() == "beamline"
assert _pre.pop() == "session"
def test_format_node_1(beamline):
......@@ -187,7 +187,7 @@ def test_format_node_1(beamline):
assert beamline.format_node(id(tn), format_string="inst.arg1->name") == "arg1"
assert not hasattr(beamline.G.node[id(tn)], "name")
assert beamline.format_node(id(tn), format_string="name->inst.arg1") == "arg1"
assert beamline.format_node("beamline", format_string="inst") == "beamline"
assert beamline.format_node("session", format_string="inst") == "session"
def test_check_formatting_1(beamline):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment