Skip to content

Commit

Permalink
fix: catched exception messed with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauric Desauw committed Oct 29, 2021
1 parent 88028f3 commit 47312c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions powerapi/cli/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def generate(self, config: Dict) -> Dict[str, Tuple[Type[Actor], StartMessage]]:
Generate an actor class and actor start message from config dict
"""
if self.component_group_name not in config:
print('CONFIG error : no ' + self.component_group_name + ' specified', file=sys.stderr)
raise PowerAPIException('CONFIG error : no ' + self.component_group_name + ' specified')
print('Configuration error : no ' + self.component_group_name + ' specified', file=sys.stderr)
raise PowerAPIException('Configuration error : no ' + self.component_group_name + ' specified')

actors = {}

Expand All @@ -64,7 +64,7 @@ def generate(self, config: Dict) -> Dict[str, Tuple[Type[Actor], StartMessage]]:
component_type = component_config['type']
actors[component_name] = self._gen_actor(component_type, component_config, config, component_name)
except KeyError as exn:
msg = 'CONFIG error : argument ' + exn.args[0]
msg = 'Configuration error : argument ' + exn.args[0]
msg += ' needed with output ' + component_type
print(msg, file=sys.stderr)
raise PowerAPIException(msg)
Expand Down Expand Up @@ -188,15 +188,15 @@ def add_db_factory(self, db_name, db_factory):

def _generate_db(self, db_name, db_config, _):
if db_name not in self.db_factory:
msg = 'CONFIG error : database type ' + db_name + 'unknow'
msg = 'Configuration error : database type ' + db_name + ' unknow'
print(msg, file=sys.stderr)
raise PowerAPIException(msg)
else:
return self.db_factory[db_name](db_config)

def _generate_model(self, model_name, db_config):
if model_name not in self.model_factory:
msg = 'CONFIG error : model type ' + model_name + 'unknow'
msg = 'Configuration error : model type ' + model_name + ' unknow'
print(msg, file=sys.stderr)
raise PowerAPIException(msg)
else:
Expand Down
2 changes: 1 addition & 1 deletion powerapi/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from __future__ import annotations

from datetime import datetime
from typing import Dict
from typing import Dict, NewType, Tuple, List
from powerapi.exception import PowerAPIExceptionWithMessage
from powerapi.message import Message

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/cli/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from powerapi.puller import PullerActor
from powerapi.database import MongoDB
from powerapi.message import PullerStartMessage, PusherStartMessage

from powerapi.exception import PowerAPIException
####################
# PULLER GENERATOR #
####################
Expand All @@ -50,7 +50,7 @@ def test_generate_puller_from_empty_config_dict_call_sys_exit(mocked_sys_exit):
args = {}
generator = PullerGenerator(None, [])

with pytest.raises(SysExitException):
with pytest.raises(PowerAPIException):
generator.generate(args)


Expand Down Expand Up @@ -170,7 +170,7 @@ def test_remove_HWPCReport_model_and_generate_puller_from_a_config_with_hwpc_rep
'db': 'tata', 'collection': 'tutu'}}}
generator = PullerGenerator(None, [])
generator.remove_model_factory('HWPCReport')
with pytest.raises(SysExitException):
with pytest.raises(PowerAPIException):
result = generator.generate(args)


Expand All @@ -180,5 +180,5 @@ def test_remove_mongodb_factory_and_generate_puller_from_a_config_with_mongodb_i
'db': 'tata', 'collection': 'tutu'}}}
generator = PullerGenerator(None, [])
generator.remove_db_factory('mongodb')
with pytest.raises(SysExitException):
with pytest.raises(PowerAPIException):
result = generator.generate(args)

0 comments on commit 47312c6

Please sign in to comment.