Skip to content

Commit

Permalink
Fixed various flake issues (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Nov 5, 2018
1 parent d175211 commit 34b14a7
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 39 deletions.
4 changes: 2 additions & 2 deletions numbergen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ class ExponentialDecay(NumberGenerator, TimeDependent):
def __call__(self):
Vi = self.starting_value
Vm = self.ending_value
return Vm + (Vi - Vm) * self.base**(-1.0*float(self.time_fn())/
float(self.time_constant))
exp = -1.0*float(self.time_fn())/float(self.time_constant)
return Vm + (Vi - Vm) * self.base**exp



Expand Down
12 changes: 6 additions & 6 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,9 @@ class Comparator(object):
@classmethod
def is_equal(cls, obj1, obj2):
for eq_type, eq in cls.equalities.items():
if ((isinstance(eq_type, FunctionType) and
eq_type(obj1) and eq_type(obj2)) or
(isinstance(obj1, eq_type) and isinstance(obj2, eq_type))):
if ((isinstance(eq_type, FunctionType)
and eq_type(obj1) and eq_type(obj2))
or (isinstance(obj1, eq_type) and isinstance(obj2, eq_type))):
return eq(obj1, obj2)
if isinstance(obj2, (list, set, tuple)):
return cls.compare_iterator(obj1, obj2)
Expand Down Expand Up @@ -1249,7 +1249,7 @@ def _spec_to_obj(self_,spec):
m = re.match("(?P<path>[^:]*):?(?P<what>.*)", spec)
what = m.group('what')
path = "."+m.group('path')
m = re.match("(?P<obj>.*)(\.)(?P<attr>.*)",path)
m = re.match(r"(?P<obj>.*)(\.)(?P<attr>.*)",path)
obj = m.group('obj')
attr = m.group("attr")

Expand Down Expand Up @@ -2025,8 +2025,8 @@ def pprint(self, imports=None, prefix=" ", unknown_value='<?>',
if k in processed: continue

# Suppresses automatically generated names.
if k == 'name' and (values[k] is not None and
re.match('^'+self.__class__.__name__+'[0-9]+$', values[k])):
if k == 'name' and (values[k] is not None
and re.match('^'+self.__class__.__name__+'[0-9]+$', values[k])):
continue

value = pprint(values[k], imports, prefix=prefix,settings=[],
Expand Down
2 changes: 1 addition & 1 deletion param/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def get_setupcfg_version():
archive_commit_key = autover_section+'.configparser_workaround.archive_commit'
for section in config.sections():
if section.startswith(archive_commit_key):
archive_commit = re.match(".*=\s*(\S*)\s*",section).group(1)
archive_commit = re.match(r".*=\s*(\S*)\s*",section).group(1)
###
return get_setup_version(cfg,reponame=reponame,pkgname=pkgname,archive_commit=archive_commit)

Expand Down
8 changes: 4 additions & 4 deletions tests/API0/testclassselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_single_class_instance_constructor(self):
def test_single_class_instance_error(self):
exception = "Parameter 'e' value must be an instance of int, not 'a'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(e='a')
self.P(e='a')

def test_single_class_type_constructor(self):
p = self.P(f=float)
Expand All @@ -36,7 +36,7 @@ def test_single_class_type_constructor(self):
def test_single_class_type_error(self):
exception = "Parameter 'str' must be a subclass of Number, not 'type'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(f=str)
self.P(f=str)

def test_multiple_class_instance_constructor1(self):
p = self.P(g=1)
Expand All @@ -49,7 +49,7 @@ def test_multiple_class_instance_constructor2(self):
def test_multiple_class_instance_error(self):
exception = "Parameter 'g' value must be an instance of \(int, str\), not '3.0'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(g=3.0)
self.P(g=3.0)

def test_multiple_class_type_constructor1(self):
p = self.P(h=int)
Expand All @@ -62,4 +62,4 @@ def test_multiple_class_type_constructor2(self):
def test_multiple_class_type_error(self):
exception = "Parameter 'float' must be a subclass of \(int, str\), not 'type'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(h=float)
self.P(h=float)
7 changes: 4 additions & 3 deletions tests/API0/testdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from param import concrete_descendents, Parameter

# import all parameter types
from param import *
from param import ClassSelector
from param import * # noqa


positional_args = {
Expand All @@ -18,12 +19,12 @@
skip = []

try:
import numpy
import numpy # noqa
except ImportError:
skip.append('Array')

try:
import pandas
import pandas # noqa
except ImportError:
skip.append('DataFrame')
skip.append('Series')
Expand Down
2 changes: 1 addition & 1 deletion tests/API0/testipythonmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


try:
import IPython
import IPython # noqa
except ImportError:
import os
if os.getenv('PARAM_TEST_IPYTHON','0') == '1':
Expand Down
8 changes: 4 additions & 4 deletions tests/API1/testclassselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_single_class_instance_constructor(self):
def test_single_class_instance_error(self):
exception = "Parameter 'e' value must be an instance of int, not 'a'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(e='a')
self.P(e='a')

def test_single_class_type_constructor(self):
p = self.P(f=float)
Expand All @@ -37,7 +37,7 @@ def test_single_class_type_constructor(self):
def test_single_class_type_error(self):
exception = "Parameter 'str' must be a subclass of Number, not 'type'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(f=str)
self.P(f=str)

def test_multiple_class_instance_constructor1(self):
p = self.P(g=1)
Expand All @@ -50,7 +50,7 @@ def test_multiple_class_instance_constructor2(self):
def test_multiple_class_instance_error(self):
exception = "Parameter 'g' value must be an instance of \(int, str\), not '3.0'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(g=3.0)
self.P(g=3.0)

def test_multiple_class_type_constructor1(self):
p = self.P(h=int)
Expand All @@ -63,7 +63,7 @@ def test_multiple_class_type_constructor2(self):
def test_multiple_class_type_error(self):
exception = "Parameter 'float' must be a subclass of \(int, str\), not 'type'"
with self.assertRaisesRegexp(ValueError, exception):
p = self.P(h=float)
self.P(h=float)


class TestDictParameters(API1TestCase):
Expand Down
7 changes: 4 additions & 3 deletions tests/API1/testdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from param import concrete_descendents, Parameter

# import all parameter types
from param import *
from param import * # noqa
from param import ClassSelector
from . import API1TestCase

positional_args = {
Expand All @@ -16,11 +17,11 @@
skip = []

try:
import numpy
import numpy # noqa
except ImportError:
skip.append('Array')
try:
import pandas
import pandas # noqa
except ImportError:
skip.append('DataFrame')
skip.append('Series')
Expand Down
2 changes: 1 addition & 1 deletion tests/API1/testipythonmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from . import API1TestCase

try:
import IPython
import IPython # noqa
except ImportError:
import os
if os.getenv('PARAM_TEST_IPYTHON','0') == '1':
Expand Down
26 changes: 13 additions & 13 deletions tests/API1/testwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_simple_batched_watch_setattr(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher = obj.param.watch(accumulator, ['a','b'])
obj.param.watch(accumulator, ['a','b'])

obj.a = 2
self.assertEqual(accumulator.call_count(), 1)
Expand Down Expand Up @@ -196,12 +196,12 @@ def test_nested_batched_watch_setattr(self):
obj = SimpleWatchExample()

accumulator = Accumulator()
watcher = obj.param.watch(accumulator, ['a', 'c'])
obj.param.watch(accumulator, ['a', 'c'])

def set_c(*events):
obj.c = 3

watcher2 = obj.param.watch(set_c, ['a', 'b'])
obj.param.watch(set_c, ['a', 'b'])

obj.param.set_param(a=2)
self.assertEqual(obj.c, 3)
Expand All @@ -216,7 +216,7 @@ def test_simple_batched_watch(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher = obj.param.watch(accumulator, ['a','b'])
obj.param.watch(accumulator, ['a','b'])
obj.param.set_param(a=23, b=42)

self.assertEqual(accumulator.call_count(), 1)
Expand Down Expand Up @@ -265,8 +265,8 @@ def test_simple_batched_watch_callback_reuse(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher1 = obj.param.watch(accumulator, ['a','b'])
watcher2 = obj.param.watch(accumulator, ['c'])
obj.param.watch(accumulator, ['a','b'])
obj.param.watch(accumulator, ['c'])

obj.param.set_param(a=23, b=42, c=99)

Expand Down Expand Up @@ -429,7 +429,7 @@ def test_simple_batched_watch_values_setattr(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher = obj.param.watch_values(accumulator, ['a','b'])
obj.param.watch_values(accumulator, ['a','b'])

obj.a = 2
self.assertEqual(accumulator.call_count(), 1)
Expand All @@ -449,7 +449,7 @@ def test_simple_batched_watch_values(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher = obj.param.watch_values(accumulator, ['a','b'])
obj.param.watch_values(accumulator, ['a','b'])
obj.param.set_param(a=23, b=42)

self.assertEqual(accumulator.call_count(), 1)
Expand All @@ -462,8 +462,8 @@ def test_simple_batched_watch_values_callback_reuse(self):
accumulator = Accumulator()

obj = SimpleWatchExample()
watcher1 = obj.param.watch_values(accumulator, ['a','b'])
watcher2 = obj.param.watch_values(accumulator, ['c'])
obj.param.watch_values(accumulator, ['a','b'])
obj.param.watch_values(accumulator, ['c'])

obj.param.set_param(a=23, b=42, c=99)

Expand All @@ -488,7 +488,7 @@ def setUp(self):
def test_simple_trigger_one_param(self):
accumulator = Accumulator()
obj = SimpleWatchExample()
watcher = obj.param.watch(accumulator, ['a'])
obj.param.watch(accumulator, ['a'])
obj.param.trigger('a')
self.assertEqual(accumulator.call_count(), 1)

Expand All @@ -501,7 +501,7 @@ def test_simple_trigger_one_param(self):
def test_simple_trigger_one_param_change(self):
accumulator = Accumulator()
obj = SimpleWatchExample()
watcher = obj.param.watch(accumulator, ['a'])
obj.param.watch(accumulator, ['a'])
obj.a = 42
self.assertEqual(accumulator.call_count(), 1)

Expand All @@ -523,7 +523,7 @@ def test_simple_trigger_one_param_change(self):
def test_simple_trigger_two_params(self):
accumulator = Accumulator()
obj = SimpleWatchExample()
watcher = obj.param.watch(accumulator, ['a','b'])
obj.param.watch(accumulator, ['a','b'])
obj.param.trigger('a','b')
self.assertEqual(accumulator.call_count(), 1)

Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
import unittest
import unittest # noqa

if sys.version_info[0]==2 and sys.version_info[1]<7:
del sys.modules['unittest']
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ setenv = PARAM_TEST_IPYTHON = 1
[testenv:flakes]
skip_install = true
commands = flake8

[flake8]
ignore = E,W,W605
include = *.py
exclude = .git,__pycache__,.tox,.eggs,*.egg,doc,dist,build,_build,.ipynb_checkpoints,run_test.py

0 comments on commit 34b14a7

Please sign in to comment.