Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid escape sequence occurences #518

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,15 @@ def __setstate__(self,state):

# Define one particular type of Parameter that is used in this file
class String(Parameter):
"""
r"""
jbednar marked this conversation as resolved.
Show resolved Hide resolved
A String Parameter, with a default value and optional regular expression (regex) matching.

Example of using a regex to implement IPv4 address matching::

class IPAddress(String):
'''IPv4 address as a string (dotted decimal notation)'''
def __init__(self, default="0.0.0.0", allow_None=False, **kwargs):
ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
super(IPAddress, self).__init__(default=default, regex=ip_regex, **kwargs)

"""
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ ignore = E114,
E743,
W503,
W504,
W605

[tool:pytest]
python_files = test*.py
# Run the doctests found (if any) in the modules of param & numbergen.
addopts = --doctest-modules param numbergen
addopts = --doctest-modules param numbergen
4 changes: 2 additions & 2 deletions tests/API0/testclassselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_multiple_class_instance_constructor2(self):
self.assertEqual(p.g, 'A')

def test_multiple_class_instance_error(self):
exception = "ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0."
exception = r"ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0."
jbednar marked this conversation as resolved.
Show resolved Hide resolved
with self.assertRaisesRegexp(ValueError, exception):
self.P(g=3.0)

Expand All @@ -60,6 +60,6 @@ def test_multiple_class_type_constructor2(self):
self.assertEqual(p.h, str)

def test_multiple_class_type_error(self):
exception = "ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'."
exception = r"ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'."
with self.assertRaisesRegexp(ValueError, exception):
self.P(h=float)
8 changes: 4 additions & 4 deletions tests/API0/testipythonmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class TestClass(param.Parameterized):
def test_parameterized_class(self):
page_string = self.pager(self.TestClass)
# Remove params automatic numbered names
page_string = re.sub('TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub('TestClass(\d+)', 'TestClass', test1_repr)
page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test1_repr)

try:
self.assertEqual(page_string, ref_string)
Expand All @@ -57,8 +57,8 @@ def test_parameterized_class(self):
def test_parameterized_instance(self):
page_string = self.pager(self.TestClass())
# Remove params automatic numbered names
page_string = re.sub('TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub('TestClass(\d+)', 'TestClass', test2_repr)
page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test2_repr)

try:
self.assertEqual(page_string, ref_string)
Expand Down
2 changes: 1 addition & 1 deletion tests/API0/teststringparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import param


ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'

class TestStringParameters(unittest.TestCase):

Expand Down
4 changes: 2 additions & 2 deletions tests/API1/testclassselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_multiple_class_instance_constructor2(self):
self.assertEqual(p.g, 'A')

def test_multiple_class_instance_error(self):
exception = "ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0."
exception = r"ClassSelector parameter 'g' value must be an instance of \(int, str\), not 3.0."
with self.assertRaisesRegexp(ValueError, exception):
self.P(g=3.0)

Expand All @@ -67,7 +67,7 @@ def test_class_selector_get_range(self):
self.assertIn('str', classes)

def test_multiple_class_type_error(self):
exception = "ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'."
exception = r"ClassSelector parameter 'h' must be a subclass of \(int, str\), not 'float'."
with self.assertRaisesRegexp(ValueError, exception):
self.P(h=float)

Expand Down
8 changes: 4 additions & 4 deletions tests/API1/testipythonmagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class TestClass(param.Parameterized):
def test_parameterized_class(self):
page_string = self.pager(self.TestClass)
# Remove params automatic numbered names
page_string = re.sub('TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub('TestClass(\d+)', 'TestClass', test1_repr)
page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test1_repr)

try:
self.assertEqual(page_string, ref_string)
Expand All @@ -57,8 +57,8 @@ def test_parameterized_class(self):
def test_parameterized_instance(self):
page_string = self.pager(self.TestClass())
# Remove params automatic numbered names
page_string = re.sub('TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub('TestClass(\d+)', 'TestClass', test2_repr)
page_string = re.sub(r'TestClass(\d+)', 'TestClass', page_string)
ref_string = re.sub(r'TestClass(\d+)', 'TestClass', test2_repr)

try:
self.assertEqual(page_string, ref_string)
Expand Down
10 changes: 5 additions & 5 deletions tests/API1/testpandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Test(param.Parameterized):

test = Test()
self.assertEquals(test.param.params('df').ordered, False)
exception = "Provided DataFrame columns \['b', 'a', 'c'\] does not contain required columns \['a', 'd'\]"
exception = r"Provided DataFrame columns \['b', 'a', 'c'\] does not contain required columns \['a', 'd'\]"
with self.assertRaisesRegexp(ValueError, exception):
test.df = invalid_df

Expand All @@ -92,7 +92,7 @@ class Test(param.Parameterized):
test = Test()
self.assertEquals(test.param.params('df').ordered, True)

exception = "Provided DataFrame columns \['a', 'b', 'd'\] must exactly match \['b', 'a', 'd'\]"
exception = r"Provided DataFrame columns \['a', 'b', 'd'\] must exactly match \['b', 'a', 'd'\]"
with self.assertRaisesRegexp(ValueError, exception):
test.df = invalid_df

Expand Down Expand Up @@ -125,7 +125,7 @@ def test_dataframe_unordered_column_tuple_invalid(self):

invalid_df = pandas.DataFrame({'a':[1,2], 'b':[2,3], 'c':[4,5]}, columns=['b', 'a', 'c'])

exception = "Columns length 3 does not match declared bounds of \(None, 2\)"
exception = r"Columns length 3 does not match declared bounds of \(None, 2\)"
with self.assertRaisesRegexp(ValueError, exception):
class Test(param.Parameterized):
df = param.DataFrame(default=invalid_df, columns=(None,2))
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_dataframe_unordered_row_tuple_invalid(self):

invalid_df = pandas.DataFrame({'a':[1,2], 'b':[2,3], 'c':[4,5]}, columns=['b', 'a', 'c'])

exception = "Row length 2 does not match declared bounds of \(5, 7\)"
exception = r"Row length 2 does not match declared bounds of \(5, 7\)"
with self.assertRaisesRegexp(ValueError, exception):
class Test(param.Parameterized):
df = param.DataFrame(default=invalid_df, rows=(5,7))
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_series_unordered_row_tuple_invalid(self):

invalid_series = pandas.Series([1,2])

exception = "Row length 2 does not match declared bounds of \(5, 7\)"
exception = r"Row length 2 does not match declared bounds of \(5, 7\)"
with self.assertRaisesRegexp(ValueError, exception):
class Test(param.Parameterized):
series = param.Series(default=invalid_series, rows=(5,7))
Expand Down
2 changes: 1 addition & 1 deletion tests/API1/teststringparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import param


ip_regex = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'
ip_regex = r'^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$'

class TestStringParameters(API1TestCase):

Expand Down