Skip to content

Commit

Permalink
Ensure py35 support (#34)
Browse files Browse the repository at this point in the history
Added py35 support.
  • Loading branch information
jraygauthier committed Mar 27, 2021
1 parent 8480dac commit dc166e3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions docs/sources/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def read_version():
with init.open('r') as pkg_init_f:
version_read = [line.strip() for line in pkg_init_f if line.startswith('__version__')]
if len(version_read) > 1:
raise ValueError(f'Multiple version found in "pytest_monitor" package!')
raise ValueError('Multiple version found in "pytest_monitor" package!')
if not version_read:
raise ValueError(f'No version found in "pytest_monitor" package!')
raise ValueError('No version found in "pytest_monitor" package!')
return version_read[0].split('=', 1)[1].strip('" \'')


Expand Down Expand Up @@ -75,7 +75,7 @@ def read_version():
# The short X.Y version.
version = read_version()
# The full version, including alpha/beta/rc tags.
release = f'pytest-monitor v{version}'
release = 'pytest-monitor v{}'.format(version)

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
20 changes: 10 additions & 10 deletions pytest_monitor/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ def query(self, what, bind_to, many=False):

def insert_session(self, h, run_date, scm_id, description):
with self.__cnx:
self.__cnx.execute(f'insert into TEST_SESSIONS(SESSION_H, RUN_DATE, SCM_ID, RUN_DESCRIPTION)'
f' values (?,?,?,?)',
self.__cnx.execute('insert into TEST_SESSIONS(SESSION_H, RUN_DATE, SCM_ID, RUN_DESCRIPTION)'
' values (?,?,?,?)',
(h, run_date, scm_id, description))

def insert_metric(self, session_id, env_id, item_start_date, item, item_path, item_variant,
item_loc, kind, component, total_time, user_time, kernel_time, cpu_usage, mem_usage):
with self.__cnx:
self.__cnx.execute(f'insert into TEST_METRICS(SESSION_H,ENV_H,ITEM_START_TIME,ITEM,'
f'ITEM_PATH,ITEM_VARIANT,ITEM_FS_LOC,KIND,COMPONENT,TOTAL_TIME,'
f'USER_TIME,KERNEL_TIME,CPU_USAGE,MEM_USAGE) '
f'values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
self.__cnx.execute('insert into TEST_METRICS(SESSION_H,ENV_H,ITEM_START_TIME,ITEM,'
'ITEM_PATH,ITEM_VARIANT,ITEM_FS_LOC,KIND,COMPONENT,TOTAL_TIME,'
'USER_TIME,KERNEL_TIME,CPU_USAGE,MEM_USAGE) '
'values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
(session_id, env_id, item_start_date, item, item_path,
item_variant, item_loc, kind, component, total_time, user_time,
kernel_time, cpu_usage, mem_usage))

def insert_execution_context(self, exc_context):
with self.__cnx:
self.__cnx.execute(f'insert into EXECUTION_CONTEXTS(CPU_COUNT,CPU_FREQUENCY_MHZ,CPU_TYPE,CPU_VENDOR,'
f'RAM_TOTAL_MB,MACHINE_NODE,MACHINE_TYPE,MACHINE_ARCH,SYSTEM_INFO,'
f'PYTHON_INFO,ENV_H) values (?,?,?,?,?,?,?,?,?,?,?)',
self.__cnx.execute('insert into EXECUTION_CONTEXTS(CPU_COUNT,CPU_FREQUENCY_MHZ,CPU_TYPE,CPU_VENDOR,'
'RAM_TOTAL_MB,MACHINE_NODE,MACHINE_TYPE,MACHINE_ARCH,SYSTEM_INFO,'
'PYTHON_INFO,ENV_H) values (?,?,?,?,?,?,?,?,?,?,?)',
(exc_context.cpu_count, exc_context.cpu_frequency, exc_context.cpu_type,
exc_context.cpu_vendor, exc_context.ram_total, exc_context.fqdn, exc_context.machine,
exc_context.architecture, exc_context.system_info, exc_context.python_info,
Expand All @@ -45,7 +45,7 @@ def prepare(self):
CREATE TABLE IF NOT EXISTS TEST_SESSIONS(
SESSION_H varchar(64) primary key not null unique, -- Session identifier
RUN_DATE varchar(64), -- Date of test run
SCM_ID varchar(128), -- SCM change id
SCM_ID varchar(128), -- SCM change id
RUN_DESCRIPTION varchar(1024)
);''')
cursor.execute('''
Expand Down
10 changes: 5 additions & 5 deletions pytest_monitor/pytest_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def pytest_addoption(parser):
group.addoption('--db', action='store', dest='mtr_db_out', default='.pymon',
help='Use the given sqlite database for storing results.')
group.addoption('--no-db', action='store_true', dest='mtr_no_db', help='Do not store results in local db.')
group.addoption('--force-component', action='store', dest='mtr_force_component',
group.addoption('--force-component', action='store', dest='mtr_force_component',
help='Force the component to be set at the given value for the all tests run'
' in this session.')
group.addoption('--component-prefix', action='store', dest='mtr_component_prefix',
Expand Down Expand Up @@ -70,10 +70,10 @@ def pytest_runtest_setup(item):
mark_to_del = []
for set_marker in item_markers.keys():
if set_marker not in PYTEST_MONITOR_VALID_MARKERS:
warnings.warn(f"Nothing known about marker {set_marker}. Marker will be dropped.")
warnings.warn("Nothing known about marker {}. Marker will be dropped.".format(set_marker))
mark_to_del.append(set_marker)
if set_marker in PYTEST_MONITOR_DEPRECATED_MARKERS:
warnings.warn(f'Marker {set_marker} is deprecated. Consider upgrading your tests')
warnings.warn('Marker {} is deprecated. Consider upgrading your tests'.format(set_marker))

for marker in mark_to_del:
del item_markers[marker]
Expand Down Expand Up @@ -148,7 +148,7 @@ def prof():

def pytest_make_parametrize_id(config, val, argname):
if config.option.mtr_want_explicit_ids:
return f'{argname}={val}'
return '{}={}'.format(argname, val)


@pytest.hookimpl(hookwrapper=True)
Expand All @@ -162,7 +162,7 @@ def pytest_sessionstart(session):
if session.config.option.mtr_no_db and not session.config.option.mtr_remote and not session.config.option.mtr_none:
warnings.warn('pytest-monitor: No storage specified but monitoring is requested. Disabling monitoring.')
session.config.option.mtr_none = True
component = session.config.option.mtr_force_component or session.config.option.mtr_component_prefix
component = session.config.option.mtr_force_component or session.config.option.mtr_component_prefix
if session.config.option.mtr_component_prefix:
component += '.{user_component}'
if not component:
Expand Down
14 changes: 7 additions & 7 deletions pytest_monitor/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_env_id(self, env):
row = self.__db.query('SELECT ENV_H FROM EXECUTION_CONTEXTS WHERE ENV_H= ?', (env.hash(),))
db = row[0] if row else None
if self.__remote:
r = requests.get(f'{self.__remote}/contexts/{env.hash()}')
r = requests.get('{}/contexts/{}'.format(self.__remote, env.hash()))
remote = None
if r.status_code == HTTPStatus.OK:
remote = json.loads(r.text)
Expand Down Expand Up @@ -81,14 +81,14 @@ def compute_info(self, description, tags):
if self.__db:
self.__db.insert_session(self.__session, run_date, scm, description)
if self.__remote:
r = requests.post(f'{self.__remote}/sessions/',
r = requests.post('{}/sessions/'.format(self.__remote),
json=dict(session_h=self.__session,
run_date=run_date,
scm_ref=scm,
description=description))
if r.status_code != HTTPStatus.CREATED:
self.__remote = ''
msg = f"Cannot insert session in remote monitor server ({r.status_code})! Deactivating...')"
msg = "Cannot insert session in remote monitor server ({})! Deactivating...')".format(r.status_code)
warnings.warn(msg)

def set_environment_info(self, env):
Expand All @@ -99,9 +99,9 @@ def set_environment_info(self, env):
db_id = self.__db.query('select ENV_H from EXECUTION_CONTEXTS where ENV_H = ?', (env.hash(),))[0]
if self.__remote and remote_id is None:
# We must postpone that to be run at the end of the pytest session.
r = requests.post(f'{self.__remote}/contexts/', json=env.to_dict())
r = requests.post('{}/contexts/'.format(self.__remote), json=env.to_dict())
if r.status_code != HTTPStatus.CREATED:
warnings.warn(f'Cannot insert execution context in remote server (rc={r.status_code}! Deactivating...')
warnings.warn('Cannot insert execution context in remote server (rc={}! Deactivating...'.format(r.status_code))
self.__remote = ''
else:
remote_id = json.loads(r.text)['h']
Expand Down Expand Up @@ -130,7 +130,7 @@ def add_test_info(self, item, item_path, item_variant, item_loc, kind, component
item_path, item_variant, item_loc, kind, final_component, total_time, user_time,
kernel_time, cpu_usage, mem_usage)
if self.__remote and self.remote_env_id is not None:
r = requests.post(f'{self.__remote}/metrics/',
r = requests.post('{}/metrics/'.format(self.__remote),
json=dict(session_h=self.__session,
context_h=self.remote_env_id,
item_start_time=item_start_time,
Expand All @@ -147,5 +147,5 @@ def add_test_info(self, item, item_path, item_variant, item_loc, kind, component
mem_usage=mem_usage))
if r.status_code != HTTPStatus.CREATED:
self.__remote = ''
msg = f"Cannot insert values in remote monitor server ({r.status_code})! Deactivating...')"
msg = "Cannot insert values in remote monitor server ({})! Deactivating...')".format(r.status_code)
warnings.warn(msg)
2 changes: 1 addition & 1 deletion pytest_monitor/sys_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self):
self.__fqdn = socket.getfqdn()
self.__machine = platform.machine()
self.__arch = platform.architecture()[0]
self.__system = f'{platform.system()} - {platform.release()}'
self.__system = '{} - {}'.format(platform.system(), platform.release())
self.__py_ver = sys.version

def to_dict(self):
Expand Down

0 comments on commit dc166e3

Please sign in to comment.