remove warnings in tests

This commit is contained in:
Emmanuel Garette 2018-08-18 16:11:25 +02:00
parent 7340ceb173
commit 5f8cd546e7
1 changed files with 199 additions and 184 deletions

View File

@ -2,6 +2,7 @@
""" """
import weakref import weakref
import pytest import pytest
import warnings
from copy import copy from copy import copy
from py.test import raises from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
@ -167,6 +168,7 @@ def _autocheck_default_value(cfg, path, conf, **kwargs):
# test default value (should be empty) # test default value (should be empty)
# cannot test for slave (we cannot get all values for a slave) # cannot test for slave (we cannot get all values for a slave)
with warnings.catch_warnings(record=True) as w:
if not isslave: if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(path).value.get() == empty_value assert cfg.config(conf).option(path).value.get() == empty_value
@ -222,6 +224,7 @@ def _set_value(cfg, pathwrite, conf, **kwargs):
# for slave should have an index and good length # for slave should have an index and good length
# for master must append, not set # for master must append, not set
with warnings.catch_warnings(record=True) as w:
if ismaster: if ismaster:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])") raises(APIError, "cfg.config(conf).option(pathwrite, 0).value.set(first_value[0])")
@ -318,6 +321,7 @@ def autocheck_get_value_permissive(cfg, pathread, pathwrite, confread, confwrite
raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get()") raises(PropertiesOptionError, "assert cfg.forcepermissive.config(conf).option(pathread, 1).value.get()")
else: else:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
with warnings.catch_warnings(record=True) as w:
assert cfg.config(conf).option(pathread).value.get() == first_value assert cfg.config(conf).option(pathread).value.get() == first_value
assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
@ -326,6 +330,7 @@ def autocheck_get_value_permissive(cfg, pathread, pathwrite, confread, confwrite
else: else:
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()")
raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()") raises(PropertiesOptionError, "cfg.forcepermissive.config(conf).option(pathread).value.get()")
with warnings.catch_warnings(record=True) as w:
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(confwrite) do(confwrite)
@ -352,6 +357,7 @@ def _autocheck_get_value(cfg, pathread, conf, **kwargs):
second_value = SUBLIST_SECOND_VALUE[1] second_value = SUBLIST_SECOND_VALUE[1]
# get value after set value without permissive # get value after set value without permissive
with warnings.catch_warnings(record=True) as w:
if isslave: if isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
assert cfg.config(conf).option(pathread, 0).value.get() == empty_value assert cfg.config(conf).option(pathread, 0).value.get() == empty_value
@ -426,6 +432,7 @@ def autocheck_value_slave(cfg, pathread, pathwrite, confread, confwrite, **kwarg
length = 2 length = 2
value = [] value = []
with warnings.catch_warnings(record=True) as w:
for idx in range(length): for idx in range(length):
value.append(cfg.forcepermissive.option(pathread, idx).value.get()) value.append(cfg.forcepermissive.option(pathread, idx).value.get())
@ -467,6 +474,7 @@ def autocheck_reset_value(cfg, pathread, pathwrite, confread, confwrite, **kwarg
_set_value(cfg, pathwrite, confwrite, **kwargs) _set_value(cfg, pathwrite, confwrite, **kwargs)
# reset value without permissive # reset value without permissive
with warnings.catch_warnings(record=True) as w:
if not isslave: if not isslave:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
cfg.config(confwrite).option(pathwrite).value.reset() cfg.config(confwrite).option(pathwrite).value.reset()
@ -494,6 +502,7 @@ def autocheck_reset_value(cfg, pathread, pathwrite, confread, confwrite, **kwarg
elif kwargs.get('permissive', False): elif kwargs.get('permissive', False):
raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()") raises(PropertiesOptionError, "cfg.config(conf).option(pathread).value.get()")
assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value assert cfg.forcepermissive.config(conf).option(pathread).value.get() == first_value
with warnings.catch_warnings(record=True) as w:
do(confread) do(confread)
if confread != confwrite: if confread != confwrite:
do(confwrite) do(confwrite)
@ -506,11 +515,13 @@ def autocheck_append_value(cfg, pathread, pathwrite, confread, confwrite, **kwar
if not ismaster: if not ismaster:
return return
with warnings.catch_warnings(record=True) as w:
if not kwargs.get('propertyerror', False): if not kwargs.get('propertyerror', False):
master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() master_value = cfg.forcepermissive.config(confread).option(pathread).value.get()
len_value = len(master_value) len_value = len(master_value)
master_value.append(undefined) master_value.append(undefined)
assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len_value assert len(cfg.forcepermissive.config(confread).option(pathread).value.get()) == len_value
with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value) cfg.forcepermissive.config(confwrite).option(pathread).value.set(master_value)
new_master_value = cfg.forcepermissive.config(confread).option(pathread).value.get() new_master_value = cfg.forcepermissive.config(confread).option(pathread).value.get()
len_new = len(new_master_value) len_new = len(new_master_value)
@ -554,6 +565,7 @@ def autocheck_pop_value(cfg, pathread, pathwrite, confread, confwrite, **kwargs)
a_slave += '.third' + a_slave[-4:] a_slave += '.third' + a_slave[-4:]
else: else:
a_slave += '.third' a_slave += '.third'
with warnings.catch_warnings(record=True) as w:
cfg.forcepermissive.config(confwrite).option(pathread).value.set(values) cfg.forcepermissive.config(confwrite).option(pathread).value.set(values)
cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value) cfg.forcepermissive.config(confwrite).option(a_slave, 1).value.set(slave_value)
cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi'] cfg.forcepermissive.config(confread).option(a_slave, 0).value.get() == kwargs['default_multi']
@ -590,6 +602,7 @@ def autocheck_reset_value_permissive(cfg, pathread, pathwrite, confread, confwri
isslave = cfg.unrestraint.option(pathread).option.isslave() isslave = cfg.unrestraint.option(pathread).option.isslave()
_set_value(cfg, pathwrite, confwrite, **kwargs) _set_value(cfg, pathwrite, confwrite, **kwargs)
# reset value with permissive # reset value with permissive
with warnings.catch_warnings(record=True) as w:
if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False): if not kwargs.get('permissive', False) and not kwargs.get('propertyerror', False):
if not isslave: if not isslave:
cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset() cfg.forcepermissive.config(confwrite).option(pathwrite).value.reset()
@ -1329,6 +1342,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
value = SUBLIST_SECOND_VALUE value = SUBLIST_SECOND_VALUE
else: else:
value = LIST_SECOND_VALUE value = LIST_SECOND_VALUE
with warnings.catch_warnings(record=True) as w:
ncfg.option(master_path).value.set(value) ncfg.option(master_path).value.set(value)
ckwargs['make_dict'][master_path] = value ckwargs['make_dict'][master_path] = value
ckwargs['make_dict_value'][master_path] = value ckwargs['make_dict_value'][master_path] = value
@ -1336,6 +1350,7 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
ckwargs['make_dict'][master_path + 'link'] = value ckwargs['make_dict'][master_path + 'link'] = value
ckwargs['make_dict_value'][master_path + 'link'] = value ckwargs['make_dict_value'][master_path + 'link'] = value
if master_path_2: if master_path_2:
with warnings.catch_warnings(record=True) as w:
ncfg.option(master_path_2).value.set(value) ncfg.option(master_path_2).value.set(value)
ckwargs['make_dict'][master_path_2] = value ckwargs['make_dict'][master_path_2] = value
ckwargs['make_dict_value'][master_path_2] = value ckwargs['make_dict_value'][master_path_2] = value