diff --git a/docs/conf.py b/docs/conf.py index dccd971e6..57c6c4918 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,9 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os, shutil +import os +import shutil +import sys on_rtd = os.environ.get("READTHEDOCS", None) == "True" @@ -56,8 +58,8 @@ master_doc = "index" # General information about the project. -project = u"pyDAL" -copyright = u"2014, web2py-developers" +project = "pyDAL" +copyright = "2014, web2py-developers" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -188,7 +190,7 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ("index", "pydal.tex", u"pyDAL Documentation", u"web2py-developers", "manual"), + ("index", "pydal.tex", "pyDAL Documentation", "web2py-developers", "manual"), ] # The name of an image file (relative to this directory) to place at the top of @@ -216,7 +218,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [("index", "pyDAL", u"pyDAL Documentation", [u"web2py-developers"], 1)] +man_pages = [("index", "pyDAL", "pyDAL Documentation", ["web2py-developers"], 1)] # If true, show URL addresses after external links. # man_show_urls = False @@ -231,8 +233,8 @@ ( "index", "pyDAL", - u"pyDAL Documentation", - u"web2py-developers", + "pyDAL Documentation", + "web2py-developers", "pyDAL", "pyDAL", "Miscellaneous", diff --git a/pydal/_compat.py b/pydal/_compat.py index 3a2192231..6411671e8 100644 --- a/pydal/_compat.py +++ b/pydal/_compat.py @@ -81,7 +81,6 @@ def to_native(obj, charset="utf8", errors="strict"): return obj return obj.encode(charset, errors) - else: import _thread as thread import builtins as builtin diff --git a/pydal/connection.py b/pydal/connection.py index 0a4dd36cf..b307a0614 100644 --- a/pydal/connection.py +++ b/pydal/connection.py @@ -139,7 +139,7 @@ def close(self, action="commit", really=True): @staticmethod def close_all_instances(action): - """ to close cleanly databases in a multithreaded environment """ + """to close cleanly databases in a multithreaded environment""" dbs = getattr(THREAD_LOCAL, "_pydal_db_instances_", {}).items() for db_uid, db_group in dbs: for db in db_group: diff --git a/pydal/contrib/imap_adapter.py b/pydal/contrib/imap_adapter.py index 8965c703c..4ffe16e7a 100644 --- a/pydal/contrib/imap_adapter.py +++ b/pydal/contrib/imap_adapter.py @@ -407,7 +407,7 @@ def header_represent(f, r): return text def encode_text(self, text, charset, errors="replace"): - """ convert text for mail to unicode""" + """convert text for mail to unicode""" if text is None: text = "" if PY2: @@ -429,7 +429,7 @@ def get_charset(self, message): return charset def get_mailboxes(self): - """ Query the mail database for mailbox names """ + """Query the mail database for mailbox names""" if self.static_names: # statically defined mailbox names self.connection.mailbox_names = self.static_names diff --git a/pydal/contrib/ipaddress.py b/pydal/contrib/ipaddress.py index 5c0d64606..1e57ae41b 100644 --- a/pydal/contrib/ipaddress.py +++ b/pydal/contrib/ipaddress.py @@ -31,7 +31,6 @@ def _compat_bytes_to_byte_vals(byt): return byt - else: def _compat_bytes_to_byte_vals(byt): @@ -55,11 +54,11 @@ def _compat_to_bytes(intval, length, endianess): assert isinstance(intval, _compat_int_types) assert endianess == "big" if length == 4: - if intval < 0 or intval >= 2 ** 32: + if intval < 0 or intval >= 2**32: raise struct.error("integer out of range for 'I' format code") return struct.pack(b"!I", intval) elif length == 16: - if intval < 0 or intval >= 2 ** 128: + if intval < 0 or intval >= 2**128: raise struct.error("integer out of range for 'QQ' format code") return struct.pack(b"!QQ", intval >> 64, intval & 0xFFFFFFFFFFFFFFFF) else: @@ -71,7 +70,6 @@ def _compat_to_bytes(intval, length, endianess): def _compat_bit_length(i): return i.bit_length() - else: def _compat_bit_length(i): @@ -1225,7 +1223,7 @@ class _BaseV4(object): __slots__ = () _version = 4 # Equivalent to 255.255.255.255 or 32 bits of 1's. - _ALL_ONES = (2 ** IPV4LENGTH) - 1 + _ALL_ONES = (2**IPV4LENGTH) - 1 _DECIMAL_DIGITS = frozenset("0123456789") # the valid octets for host and netmasks. only useful for IPv4. @@ -1740,7 +1738,7 @@ class _BaseV6(object): __slots__ = () _version = 6 - _ALL_ONES = (2 ** IPV6LENGTH) - 1 + _ALL_ONES = (2**IPV6LENGTH) - 1 _HEXTET_COUNT = 8 _HEX_DIGITS = frozenset("0123456789ABCDEFabcdef") _max_prefixlen = IPV6LENGTH diff --git a/pydal/contrib/portalocker.py b/pydal/contrib/portalocker.py index 9371e7742..57ca22c86 100644 --- a/pydal/contrib/portalocker.py +++ b/pydal/contrib/portalocker.py @@ -138,7 +138,6 @@ def unlock(file): overlapped = OVERLAPPED() UnlockFileEx(hfile, 0, 0, 0xFFFF0000, ctypes.byref(overlapped)) - elif os_locking == "posix": LOCK_EX = fcntl.LOCK_EX LOCK_SH = fcntl.LOCK_SH @@ -150,7 +149,6 @@ def lock(file, flags): def unlock(file): fcntl.flock(file.fileno(), fcntl.LOCK_UN) - else: if os_locking != "gae": logger.debug("no file locking, this will cause problems") diff --git a/pydal/default_validators.py b/pydal/default_validators.py index 12f6b5f3e..0e83acfb2 100644 --- a/pydal/default_validators.py +++ b/pydal/default_validators.py @@ -65,11 +65,11 @@ def default_validators(db, field): elif field_type == "double" or field_type == "float": requires.append(validators.IS_FLOAT_IN_RANGE(-1e100, 1e100)) elif field_type == "integer": - requires.append(validators.IS_INT_IN_RANGE(-(2 ** 31), 2 ** 31)) + requires.append(validators.IS_INT_IN_RANGE(-(2**31), 2**31)) elif field_type == "bigint": - requires.append(validators.IS_INT_IN_RANGE(-(2 ** 63), 2 ** 63)) + requires.append(validators.IS_INT_IN_RANGE(-(2**63), 2**63)) elif field_type.startswith("decimal"): - requires.append(validators.IS_DECIMAL_IN_RANGE(-(10 ** 10), 10 ** 10)) + requires.append(validators.IS_DECIMAL_IN_RANGE(-(10**10), 10**10)) elif field_type == "date": requires.append(validators.IS_DATE()) elif field_type == "time": diff --git a/pydal/dialects/base.py b/pydal/dialects/base.py index 4b7fb8c6d..cde8bbf2d 100644 --- a/pydal/dialects/base.py +++ b/pydal/dialects/base.py @@ -501,17 +501,13 @@ def gte(self, first, second=None, query_env={}): ) def _is_numerical(self, field_type): - return ( - field_type - in ( - "integer", - "float", - "double", - "bigint", - "boolean", - ) - or field_type.startswith("decimal") - ) + return field_type in ( + "integer", + "float", + "double", + "bigint", + "boolean", + ) or field_type.startswith("decimal") def add(self, first, second, query_env={}): if self._is_numerical(first.type) or isinstance(first.type, Field): diff --git a/pydal/dialects/mongo.py b/pydal/dialects/mongo.py index eec3d11a0..c959a3a38 100644 --- a/pydal/dialects/mongo.py +++ b/pydal/dialects/mongo.py @@ -536,7 +536,9 @@ def lower(self, first, query_env={}): def upper(self, first, query_env={}): return {"$toUpper": self.expand(first, query_env=query_env)} - def regexp(self, first, second, match_parameter=None, case_sensitive=True, query_env={}): + def regexp( + self, first, second, match_parameter=None, case_sensitive=True, query_env={} + ): """MongoDB provides regular expression capabilities for pattern matching strings in queries. MongoDB uses Perl compatible regular expressions (i.e. 'PCRE') version 8.36 with UTF-8 support. diff --git a/pydal/dialects/oracle.py b/pydal/dialects/oracle.py index 04fed4954..dcd4760d9 100644 --- a/pydal/dialects/oracle.py +++ b/pydal/dialects/oracle.py @@ -172,14 +172,16 @@ def eq(self, first, second=None, query_env={}): def regexp(self, first, second, match_parameter, query_env={}): if match_parameter: - _match_parameter = ","+self.expand(match_parameter, "string", query_env=query_env) + _match_parameter = "," + self.expand( + match_parameter, "string", query_env=query_env + ) else: _match_parameter = "" return "REGEXP_LIKE(%s, %s %s)" % ( self.expand(first, query_env=query_env), self.expand(second, "string", query_env=query_env), - _match_parameter + _match_parameter, ) def insert(self, table, fields, values): diff --git a/pydal/dialects/postgre.py b/pydal/dialects/postgre.py index 3ae9bc91b..aa3525e22 100644 --- a/pydal/dialects/postgre.py +++ b/pydal/dialects/postgre.py @@ -303,7 +303,7 @@ def st_asgeojson(self, first, second, query_env={}): ) def json_key(self, first, key, query_env=None): - """ Get the json in key which you can use for more queries """ + """Get the json in key which you can use for more queries""" if isinstance(key, basestring): key = self.expand(key, "string", query_env=query_env) elif not isinstance(key, integer_types): @@ -311,7 +311,7 @@ def json_key(self, first, key, query_env=None): return "%s->%s" % (self.expand(first, query_env=query_env or {}), key) def json_key_value(self, first, key, query_env=None): - """ Get the value int or text in key """ + """Get the value int or text in key""" if isinstance(key, basestring): key = self.expand(key, "string", query_env=query_env) elif isinstance(key, integer_types): @@ -321,11 +321,11 @@ def json_key_value(self, first, key, query_env=None): return "%s->>%s" % (self.expand(first, query_env=query_env or {}), key) def json_path(self, first, path, query_env=None): - """ Get the json in path which you can use for more queries """ + """Get the json in path which you can use for more queries""" return "%s#>'%s'" % (self.expand(first, query_env=query_env or {}), path) def json_path_value(self, first, path, query_env=None): - """ Get the json in path which you can use for more queries """ + """Get the json in path which you can use for more queries""" return "%s#>>'%s'" % (self.expand(first, query_env=query_env or {}), path) # JSON Queries diff --git a/pydal/dialects/snowflake.py b/pydal/dialects/snowflake.py index f3c7a6fb8..cbd1fbcc3 100644 --- a/pydal/dialects/snowflake.py +++ b/pydal/dialects/snowflake.py @@ -98,7 +98,6 @@ def select( else: whr2 = self.where("w_row > %i" % lmin) - return "SELECT%s%s%s %s FROM %s%s%s%s;" % ( dst, limit, @@ -232,10 +231,10 @@ def st_asgeojson(self, first, second, query_env={}): second["precision"], second["options"], ) - + def unquote(self, val): - if (val[0] == '"' and val[-1] == '"'): - val=val.replace('"','') + if val[0] == '"' and val[-1] == '"': + val = val.replace('"', "") return val def st_astext(self, first, query_env={}): diff --git a/pydal/helpers/classes.py b/pydal/helpers/classes.py index b3189f56e..83377e21c 100644 --- a/pydal/helpers/classes.py +++ b/pydal/helpers/classes.py @@ -488,8 +488,11 @@ def try_create_web2py_filesystem(db): raise NotImplementedError( "DatabaseStoredFile only supported by mysql, potresql, sqlite" ) - blobType = "BYTEA" if db._adapter.dbengine == "postgres" else "BLOB" - sql = "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content %(blobType)s, PRIMARY KEY(path));" % {"blobType": blobType} + blobType = "BYTEA" if db._adapter.dbengine == "postgres" else "BLOB" + sql = ( + "CREATE TABLE IF NOT EXISTS web2py_filesystem (path VARCHAR(255), content %(blobType)s, PRIMARY KEY(path));" + % {"blobType": blobType} + ) if db._adapter.dbengine == "mysql": sql = sql[:-1] + " ENGINE=InnoDB;" db.executesql(sql) @@ -547,8 +550,11 @@ def close_connection(self): self.db.executesql( "DELETE FROM web2py_filesystem WHERE path='%s'" % self.filename ) - placeholder = "?" if self.db._adapter.dbengine == "sqlite" else "%s" - query = "INSERT INTO web2py_filesystem(path,content) VALUES (%(placeholder)s, %(placeholder)s)" % {"placeholder": placeholder} + placeholder = "?" if self.db._adapter.dbengine == "sqlite" else "%s" + query = ( + "INSERT INTO web2py_filesystem(path,content) VALUES (%(placeholder)s, %(placeholder)s)" + % {"placeholder": placeholder} + ) args = (self.filename, self.data) self.db.executesql(query, args) self.db.commit() diff --git a/pydal/migrator.py b/pydal/migrator.py index 4d84b0ab9..8030a179b 100644 --- a/pydal/migrator.py +++ b/pydal/migrator.py @@ -317,8 +317,8 @@ def create_table(self, table, migrate=True, fake_migrate=False, polymodel=None): uri = self.adapter.uri if isinstance(self, InDBMigrator): # No filesystem path should be used when storing table details in database. - dbpath = '' - self.adapter.folder = '' + dbpath = "" + self.adapter.folder = "" elif uri.startswith("sqlite:///") or uri.startswith("spatialite:///"): if PY2: path_encoding = ( @@ -586,7 +586,12 @@ def log(self, message, table=None): writelog = bool(logfilename) if writelog: isabs = os.path.isabs(logfilename) - if table and table._dbt and writelog and (self.adapter.folder or isinstance(self, InDBMigrator)): + if ( + table + and table._dbt + and writelog + and (self.adapter.folder or isinstance(self, InDBMigrator)) + ): if isabs: table._loggername = logfilename else: diff --git a/pydal/objects.py b/pydal/objects.py index 718be00aa..3fc66328b 100644 --- a/pydal/objects.py +++ b/pydal/objects.py @@ -46,8 +46,8 @@ "string": 512, "password": 512, "upload": 512, - "text": 2 ** 15, - "blob": 2 ** 31, + "text": 2**15, + "blob": 2**31, } DEFAULT_REGEX = { @@ -600,7 +600,7 @@ def _filter_fields(self, record, id=False): ) def _build_query(self, key): - """ for keyed table only """ + """for keyed table only""" query = None for k, v in iteritems(key): if k in self._primarykey: @@ -885,7 +885,7 @@ def _validate_fields(self, fields, defattr="default", id=None): def validate_and_insert(self, **fields): response, new_fields = self._validate_fields(fields, "default") if not response.get("errors"): - response["id"]= self.insert(**new_fields) + response["id"] = self.insert(**new_fields) return response def validate_and_update(self, _key, **fields): @@ -1580,7 +1580,9 @@ def ilike(self, value, escape=None): return self.like(value, case_sensitive=False, escape=escape) def regexp(self, value, match_parameter=None): - return Query(self.db, self._dialect.regexp, self, value, match_parameter=match_parameter) + return Query( + self.db, self._dialect.regexp, self, value, match_parameter=match_parameter + ) def belongs(self, *value, **kwattr): """ @@ -1637,17 +1639,13 @@ def contains(self, value, all=False, case_sensitive=False): return self.contains("") else: return reduce(all and AND or OR, subqueries) - if ( - self.type - not in ( - "string", - "text", - "json", - "jsonb", - "upload", - ) - and not self.type.startswith("list:") - ): + if self.type not in ( + "string", + "text", + "json", + "jsonb", + "upload", + ) and not self.type.startswith("list:"): raise SyntaxError("contains used with incompatible field type") return Query( self.db, self._dialect.contains, self, value, case_sensitive=case_sensitive @@ -2072,7 +2070,9 @@ def store(self, file, filename=None, path=None): uuid_key = self._db.uuid().replace("-", "")[-16:] if self._db else uuidstr() encoded_filename = to_native(base64.urlsafe_b64encode(to_bytes(filename))) newfilename = "%s.%s.%s.%s" % ( - self._tablename if '_tablename' in self.__dir__() and self._tablename else 'no_table', + self._tablename + if "_tablename" in self.__dir__() and self._tablename + else "no_table", self.name, uuid_key, encoded_filename, diff --git a/pydal/restapi.py b/pydal/restapi.py index e07b87b93..4765bf1ff 100644 --- a/pydal/restapi.py +++ b/pydal/restapi.py @@ -253,7 +253,7 @@ def __call__( return {"deleted": deleted} def table_model(self, table, fieldnames): - """ converts a table into its form template """ + """converts a table into its form template""" items = [] fields = post_fields = put_fields = table.fields if self.policy: diff --git a/pydal/validators.py b/pydal/validators.py index 343a98d5b..c2ed75eb2 100644 --- a/pydal/validators.py +++ b/pydal/validators.py @@ -1443,7 +1443,7 @@ def formatter(self, value, row=None): # Defined in RFC 3490, Section 3.1, Requirement #1 # Use this regex to split the authority component of a unicode URL into # its component labels -REGEX_AUTHORITY_SPLITTER = u"[\u002e\u3002\uff0e\uff61]" +REGEX_AUTHORITY_SPLITTER = "[\u002e\u3002\uff0e\uff61]" def escape_unicode(string): @@ -1562,7 +1562,7 @@ def unicode_to_ascii_url(url, prepend_scheme): if not components.netloc: # Try appending a scheme to see if that fixes the problem scheme_to_prepend = prepend_scheme or "http" - components = urlparse.urlparse(to_unicode(scheme_to_prepend) + u"://" + url) + components = urlparse.urlparse(to_unicode(scheme_to_prepend) + "://" + url) prepended = True # if we still can't find the authority @@ -4457,7 +4457,7 @@ def formatter(self, value): def calc_entropy(string): - """ calculates a simple entropy for a given string """ + """calculates a simple entropy for a given string""" alphabet = 0 # alphabet size other = set() seen = set() diff --git a/setup.py b/setup.py index 14c43840a..2b8651efc 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,9 @@ * `documentation `_ """ -import re import ast +import re + from setuptools import setup _version_re = re.compile(r"__version__\s+=\s+(.*)") diff --git a/tests/__init__.py b/tests/__init__.py index c72c5c3dc..f61dce4df 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -6,12 +6,12 @@ from .sql import * from .indexes import * -from .validation import * -from .caching import TestCache -from .smart_query import * from .base import * +from .caching import TestCache from .contribs import * -from .validators import * from .is_url_validators import * from .restapi import * +from .smart_query import * from .tags import * +from .validation import * +from .validators import * diff --git a/tests/_helpers.py b/tests/_helpers.py index 69e2bbed7..05a00ce4c 100644 --- a/tests/_helpers.py +++ b/tests/_helpers.py @@ -1,7 +1,8 @@ -from ._compat import unittest -from ._adapt import DEFAULT_URI, drop from pydal import DAL +from ._adapt import DEFAULT_URI, drop +from ._compat import unittest + class DALtest(unittest.TestCase): def __init__(self, *args, **kwargs): diff --git a/tests/base.py b/tests/base.py index 3c9739d05..293ec7210 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,13 +1,15 @@ # -*- coding: utf-8 -*- -import tempfile import shutil +import tempfile -from ._compat import unittest -from ._adapt import DEFAULT_URI, drop, IS_MSSQL, IS_IMAP, IS_GAE, IS_TERADATA, IS_ORACLE from pydal import DAL, Field from pydal._compat import PY2 +from ._adapt import (DEFAULT_URI, IS_GAE, IS_IMAP, IS_MSSQL, IS_ORACLE, + IS_TERADATA, drop) +from ._compat import unittest + @unittest.skipIf(IS_IMAP, "Reference not Null unsupported on IMAP") @unittest.skipIf(IS_ORACLE, "Reference Not Null unsupported on Oracle") @@ -204,20 +206,19 @@ def testRun(self): @unittest.skip("") class TestSingleTransaction(unittest.TestCase): - def test_single_transaction(self): - + db = DAL(DEFAULT_URI) - db.define_table('tt', Field('aa')) + db.define_table("tt", Field("aa")) self.assertEqual(db(db.tt).count(), 0) db.commit() try: with db.single_transaction(): - db.tt.insert(aa='test') - 1/0 + db.tt.insert(aa="test") + 1 / 0 except ZeroDivisionError: pass self.assertEqual(db(db.tt).count(), 0) with db.single_transaction(): - db.tt.insert(aa='test') + db.tt.insert(aa="test") self.assertEqual(db(db.tt).count(), 1) diff --git a/tests/caching.py b/tests/caching.py index b22809997..a7d2cc392 100644 --- a/tests/caching.py +++ b/tests/caching.py @@ -1,8 +1,10 @@ -import time import pickle +import time + from pydal import DAL, Field -from ._compat import unittest + from ._adapt import DEFAULT_URI, IS_IMAP, IS_MSSQL +from ._compat import unittest from ._helpers import DALtest diff --git a/tests/contribs.py b/tests/contribs.py index 2762ec2c3..282f2202a 100644 --- a/tests/contribs.py +++ b/tests/contribs.py @@ -1,11 +1,13 @@ import os import threading import time -from ._compat import unittest -from ._adapt import IS_GAE + from pydal._compat import to_bytes -from pydal.contrib.portalocker import lock, unlock, read_locked, write_locked -from pydal.contrib.portalocker import LockedFile, LOCK_EX +from pydal.contrib.portalocker import (LOCK_EX, LockedFile, lock, read_locked, + unlock, write_locked) + +from ._adapt import IS_GAE +from ._compat import unittest def tearDownModule(): diff --git a/tests/indexes.py b/tests/indexes.py index f8c19e7f4..5e6c37d5f 100644 --- a/tests/indexes.py +++ b/tests/indexes.py @@ -1,6 +1,7 @@ from pydal import DAL, Field -from ._compat import unittest + from ._adapt import DEFAULT_URI, IS_POSTGRESQL, drop +from ._compat import unittest class TestIndexesBasic(unittest.TestCase): diff --git a/tests/is_url_validators.py b/tests/is_url_validators.py index 4f41d6471..7ce4279ea 100644 --- a/tests/is_url_validators.py +++ b/tests/is_url_validators.py @@ -6,8 +6,8 @@ import unittest -from pydal.validators import IS_URL, IS_HTTP_URL, IS_GENERIC_URL -from pydal.validators import unicode_to_ascii_authority +from pydal.validators import (IS_GENERIC_URL, IS_HTTP_URL, IS_URL, + unicode_to_ascii_authority) class TestIsUrl(unittest.TestCase): @@ -561,42 +561,42 @@ class TestUnicode(unittest.TestCase): def testUnicodeToAsciiUrl(self): self.assertEqual( - unicode_to_ascii_authority(u"www.Alliancefran\xe7aise.nu"), + unicode_to_ascii_authority("www.Alliancefran\xe7aise.nu"), "www.xn--alliancefranaise-npb.nu", ) - self.assertEqual(unicode_to_ascii_authority(u"www.benn.ca"), "www.benn.ca") + self.assertEqual(unicode_to_ascii_authority("www.benn.ca"), "www.benn.ca") self.assertRaises( - UnicodeError, unicode_to_ascii_authority, u"\u4e2d" * 1000 + UnicodeError, unicode_to_ascii_authority, "\u4e2d" * 1000 ) # label is too long def testValidUrls(self): self.assertEqual( - self.x(u"www.Alliancefrancaise.nu"), + self.x("www.Alliancefrancaise.nu"), ("http://www.Alliancefrancaise.nu", None), ) self.assertEqual( - self.x(u"www.Alliancefran\xe7aise.nu"), + self.x("www.Alliancefran\xe7aise.nu"), ("http://www.xn--alliancefranaise-npb.nu", None), ) self.assertEqual( - self.x(u"www.Alliancefran\xe7aise.nu:8080"), + self.x("www.Alliancefran\xe7aise.nu:8080"), ("http://www.xn--alliancefranaise-npb.nu:8080", None), ) self.assertEqual( - self.x(u"http://www.Alliancefran\xe7aise.nu"), + self.x("http://www.Alliancefran\xe7aise.nu"), ("http://www.xn--alliancefranaise-npb.nu", None), ) self.assertEqual( - self.x(u"http://www.Alliancefran\xe7aise.nu/parnaise/blue"), + self.x("http://www.Alliancefran\xe7aise.nu/parnaise/blue"), ("http://www.xn--alliancefranaise-npb.nu/parnaise/blue", None), ) self.assertEqual( - self.x(u"http://www.Alliancefran\xe7aise.nu/parnaise/blue#fragment"), + self.x("http://www.Alliancefran\xe7aise.nu/parnaise/blue#fragment"), ("http://www.xn--alliancefranaise-npb.nu/parnaise/blue#fragment", None), ) self.assertEqual( self.x( - u"http://www.Alliancefran\xe7aise.nu/parnaise/blue?query=value#fragment" + "http://www.Alliancefran\xe7aise.nu/parnaise/blue?query=value#fragment" ), ( "http://www.xn--alliancefranaise-npb.nu/parnaise/blue?query=value#fragment", @@ -605,7 +605,7 @@ def testValidUrls(self): ) self.assertEqual( self.x( - u"http://www.Alliancefran\xe7aise.nu:8080/parnaise/blue?query=value#fragment" + "http://www.Alliancefran\xe7aise.nu:8080/parnaise/blue?query=value#fragment" ), ( "http://www.xn--alliancefranaise-npb.nu:8080/parnaise/blue?query=value#fragment", @@ -613,104 +613,104 @@ def testValidUrls(self): ), ) self.assertEqual( - self.x(u"www.Alliancefran\xe7aise.nu/parnaise/blue?query=value#fragment"), + self.x("www.Alliancefran\xe7aise.nu/parnaise/blue?query=value#fragment"), ( "http://www.xn--alliancefranaise-npb.nu/parnaise/blue?query=value#fragment", None, ), ) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.com"), ("http://xn--fiq13b.com", None) + self.x("http://\u4e2d\u4fd4.com"), ("http://xn--fiq13b.com", None) ) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.com/\u4e86"), + self.x("http://\u4e2d\u4fd4.com/\u4e86"), ("http://xn--fiq13b.com/%4e%86", None), ) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.com/\u4e86?query=\u4e86"), + self.x("http://\u4e2d\u4fd4.com/\u4e86?query=\u4e86"), ("http://xn--fiq13b.com/%4e%86?query=%4e%86", None), ) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.com/\u4e86?query=\u4e86#fragment"), + self.x("http://\u4e2d\u4fd4.com/\u4e86?query=\u4e86#fragment"), ("http://xn--fiq13b.com/%4e%86?query=%4e%86#fragment", None), ) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.com?query=\u4e86#fragment"), + self.x("http://\u4e2d\u4fd4.com?query=\u4e86#fragment"), ("http://xn--fiq13b.com?query=%4e%86#fragment", None), ) self.assertEqual( - self.x(u"http://B\xfccher.ch"), ("http://xn--bcher-kva.ch", None) + self.x("http://B\xfccher.ch"), ("http://xn--bcher-kva.ch", None) ) self.assertEqual( - self.x(u"http://\xe4\xf6\xfc\xdf.com"), ("http://xn--ss-uia6e4a.com", None) + self.x("http://\xe4\xf6\xfc\xdf.com"), ("http://xn--ss-uia6e4a.com", None) ) self.assertEqual( - self.x(u"http://visegr\xe1d.com"), ("http://xn--visegrd-mwa.com", None) + self.x("http://visegr\xe1d.com"), ("http://xn--visegrd-mwa.com", None) ) self.assertEqual( - self.x(u"http://h\xe1zipatika.com"), ("http://xn--hzipatika-01a.com", None) + self.x("http://h\xe1zipatika.com"), ("http://xn--hzipatika-01a.com", None) ) self.assertEqual( - self.x(u"http://www.\xe7ukurova.com"), + self.x("http://www.\xe7ukurova.com"), ("http://www.xn--ukurova-txa.com", None), ) self.assertEqual( - self.x(u"http://nixier\xf6hre.nixieclock-tube.com"), + self.x("http://nixier\xf6hre.nixieclock-tube.com"), ("http://xn--nixierhre-57a.nixieclock-tube.com", None), ) - self.assertEqual(self.x(u"google.ca."), ("http://google.ca.", None)) + self.assertEqual(self.x("google.ca."), ("http://google.ca.", None)) - self.assertEqual(self.y(u"https://google.ca"), ("https://google.ca", None)) + self.assertEqual(self.y("https://google.ca"), ("https://google.ca", None)) self.assertEqual( - self.y(u"https://\u4e2d\u4fd4.com"), ("https://xn--fiq13b.com", None) + self.y("https://\u4e2d\u4fd4.com"), ("https://xn--fiq13b.com", None) ) - self.assertEqual(self.z(u"google.ca"), ("google.ca", None)) + self.assertEqual(self.z("google.ca"), ("google.ca", None)) def testInvalidUrls(self): - self.assertEqual(self.x(u"://ABC.com"), (u"://ABC.com", "Enter a valid URL")) + self.assertEqual(self.x("://ABC.com"), ("://ABC.com", "Enter a valid URL")) self.assertEqual( - self.x(u"http://\u4e2d\u4fd4.dne"), - (u"http://\u4e2d\u4fd4.dne", "Enter a valid URL"), + self.x("http://\u4e2d\u4fd4.dne"), + ("http://\u4e2d\u4fd4.dne", "Enter a valid URL"), ) self.assertEqual( - self.x(u"https://google.dne"), (u"https://google.dne", "Enter a valid URL") + self.x("https://google.dne"), ("https://google.dne", "Enter a valid URL") ) self.assertEqual( - self.x(u"https://google..ca"), (u"https://google..ca", "Enter a valid URL") + self.x("https://google..ca"), ("https://google..ca", "Enter a valid URL") ) - self.assertEqual(self.x(u"google..ca"), (u"google..ca", "Enter a valid URL")) + self.assertEqual(self.x("google..ca"), ("google..ca", "Enter a valid URL")) self.assertEqual( - self.x(u"http://" + u"\u4e2d" * 1000 + u".com"), - (u"http://" + u"\u4e2d" * 1000 + u".com", "Enter a valid URL"), + self.x("http://" + "\u4e2d" * 1000 + ".com"), + ("http://" + "\u4e2d" * 1000 + ".com", "Enter a valid URL"), ) self.assertEqual( - self.x(u"http://google.com#fragment_\u4e86"), - (u"http://google.com#fragment_\u4e86", "Enter a valid URL"), + self.x("http://google.com#fragment_\u4e86"), + ("http://google.com#fragment_\u4e86", "Enter a valid URL"), ) self.assertEqual( - self.x(u"http\u4e86://google.com"), - (u"http\u4e86://google.com", "Enter a valid URL"), + self.x("http\u4e86://google.com"), + ("http\u4e86://google.com", "Enter a valid URL"), ) self.assertEqual( - self.x(u"http\u4e86://google.com#fragment_\u4e86"), - (u"http\u4e86://google.com#fragment_\u4e86", "Enter a valid URL"), + self.x("http\u4e86://google.com#fragment_\u4e86"), + ("http\u4e86://google.com#fragment_\u4e86", "Enter a valid URL"), ) self.assertEqual( - self.y(u"http://\u4e2d\u4fd4.com/\u4e86"), - (u"http://\u4e2d\u4fd4.com/\u4e86", "Enter a valid URL"), + self.y("http://\u4e2d\u4fd4.com/\u4e86"), + ("http://\u4e2d\u4fd4.com/\u4e86", "Enter a valid URL"), ) # self.assertEqual(self.y(u'google.ca'), (u'google.ca', 'Enter a valid URL')) self.assertEqual( - self.z(u"invalid.domain..com"), - (u"invalid.domain..com", "Enter a valid URL"), + self.z("invalid.domain..com"), + ("invalid.domain..com", "Enter a valid URL"), ) self.assertEqual( - self.z(u"invalid.\u4e2d\u4fd4.blargg"), - (u"invalid.\u4e2d\u4fd4.blargg", "Enter a valid URL"), + self.z("invalid.\u4e2d\u4fd4.blargg"), + ("invalid.\u4e2d\u4fd4.blargg", "Enter a valid URL"), ) diff --git a/tests/nosql.py b/tests/nosql.py index ba77d68dc..eee4776a6 100644 --- a/tests/nosql.py +++ b/tests/nosql.py @@ -4,18 +4,20 @@ """ from __future__ import print_function -import sys -import os -import glob + import datetime -from ._compat import unittest +import glob +import os +import sys -from pydal._compat import PY2, basestring, StringIO, to_bytes, long from pydal import DAL, Field -from pydal.objects import Table, Query, Expression -from pydal.helpers.classes import SQLALL, OpRow +from pydal._compat import PY2, StringIO, basestring, long, to_bytes from pydal.exceptions import NotOnNOSQLError -from ._adapt import DEFAULT_URI, IS_IMAP, drop, IS_GAE, IS_MONGODB, _quote +from pydal.helpers.classes import SQLALL, OpRow +from pydal.objects import Expression, Query, Table + +from ._adapt import DEFAULT_URI, IS_GAE, IS_IMAP, IS_MONGODB, _quote, drop +from ._compat import unittest if IS_IMAP: from pydal.adapters import IMAPAdapter @@ -300,14 +302,14 @@ def testFieldName(self): # Check that Field names don't allow a unicode string non_valid_examples = non_valid_examples = [ "ℙƴ☂ℌøἤ", - u"ℙƴ☂ℌøἤ", - u"àè", - u"ṧøмℯ", - u"тεṧт", - u"♥αłüℯṧ", - u"ℊεᾔ℮яαт℮∂", - u"♭ƴ", - u"ᾔ☤ρℌℓ☺ḓ", + "ℙƴ☂ℌøἤ", + "àè", + "ṧøмℯ", + "тεṧт", + "♥αłüℯṧ", + "ℊεᾔ℮яαт℮∂", + "♭ƴ", + "ᾔ☤ρℌℓ☺ḓ", ] for a in non_valid_examples: self.assertRaises(SyntaxError, Field, a, "string") @@ -504,14 +506,14 @@ def testTableNames(self): # Check that Table names don't allow a unicode string non_valid_examples = [ "ℙƴ☂ℌøἤ", - u"ℙƴ☂ℌøἤ", - u"àè", - u"ṧøмℯ", - u"тεṧт", - u"♥αłüℯṧ", - u"ℊεᾔ℮яαт℮∂", - u"♭ƴ", - u"ᾔ☤ρℌℓ☺ḓ", + "ℙƴ☂ℌøἤ", + "àè", + "ṧøмℯ", + "тεṧт", + "♥αłüℯṧ", + "ℊεᾔ℮яαт℮∂", + "♭ƴ", + "ᾔ☤ρℌℓ☺ḓ", ] for a in non_valid_examples: self.assertRaises(SyntaxError, Table, None, a) diff --git a/tests/restapi.py b/tests/restapi.py index 68fc454e5..a5fb9560b 100644 --- a/tests/restapi.py +++ b/tests/restapi.py @@ -1,8 +1,9 @@ import unittest from pydal import DAL, Field +from pydal.restapi import (ALLOW_ALL_POLICY, DENY_ALL_POLICY, RestAPI, + __version__) from pydal.validators import IS_NOT_IN_DB -from pydal.restapi import RestAPI, ALLOW_ALL_POLICY, DENY_ALL_POLICY, __version__ class TestRestAPI(unittest.TestCase): diff --git a/tests/smart_query.py b/tests/smart_query.py index 6c22e4b90..e241c0e25 100644 --- a/tests/smart_query.py +++ b/tests/smart_query.py @@ -1,9 +1,10 @@ -from ._compat import unittest -from ._adapt import DEFAULT_URI, IS_GAE, IS_IMAP, drop -from pydal._compat import integer_types from pydal import DAL, Field +from pydal._compat import integer_types from pydal.helpers.methods import smart_query +from ._adapt import DEFAULT_URI, IS_GAE, IS_IMAP, drop +from ._compat import unittest + @unittest.skipIf(IS_IMAP, "Skip nosql") class TestSmartQuery(unittest.TestCase): diff --git a/tests/sql.py b/tests/sql.py index e5f68c0da..48bf55c98 100644 --- a/tests/sql.py +++ b/tests/sql.py @@ -4,29 +4,23 @@ """ from __future__ import print_function -import os -import glob + import datetime +import glob import json +import os import pickle from unittest import skipIf -from pydal._compat import basestring, StringIO, integer_types, xrange, BytesIO, to_bytes, PY2 from pydal import DAL, Field +from pydal._compat import (PY2, BytesIO, StringIO, basestring, integer_types, + to_bytes, xrange) from pydal.helpers.classes import SQLALL, OpRow -from pydal.objects import Table, Expression, Row -from ._compat import unittest -from ._adapt import ( - DEFAULT_URI, - IS_POSTGRESQL, - IS_SQLITE, - IS_MSSQL, - IS_MYSQL, - IS_TERADATA, - IS_NOSQL, - IS_ORACLE, -) +from pydal.objects import Expression, Row, Table +from ._adapt import (DEFAULT_URI, IS_MSSQL, IS_MYSQL, IS_NOSQL, IS_ORACLE, + IS_POSTGRESQL, IS_SQLITE, IS_TERADATA) +from ._compat import unittest from ._helpers import DALtest long = integer_types[-1] @@ -132,14 +126,14 @@ def testFieldName(self): # Check that Field names don't allow a unicode string non_valid_examples = non_valid_examples = [ "ℙƴ☂ℌøἤ", - u"ℙƴ☂ℌøἤ", - u"àè", - u"ṧøмℯ", - u"тεṧт", - u"♥αłüℯṧ", - u"ℊεᾔ℮яαт℮∂", - u"♭ƴ", - u"ᾔ☤ρℌℓ☺ḓ", + "ℙƴ☂ℌøἤ", + "àè", + "ṧøмℯ", + "тεṧт", + "♥αłüℯṧ", + "ℊεᾔ℮яαт℮∂", + "♭ƴ", + "ᾔ☤ρℌℓ☺ḓ", ] for a in non_valid_examples: self.assertRaises(SyntaxError, Field, a, "string") @@ -428,14 +422,14 @@ def testTableNames(self): # Check that Table names don't allow a unicode string non_valid_examples = [ "ℙƴ☂ℌøἤ", - u"ℙƴ☂ℌøἤ", - u"àè", - u"ṧøмℯ", - u"тεṧт", - u"♥αłüℯṧ", - u"ℊεᾔ℮яαт℮∂", - u"♭ƴ", - u"ᾔ☤ρℌℓ☺ḓ", + "ℙƴ☂ℌøἤ", + "àè", + "ṧøмℯ", + "тεṧт", + "♥αłüℯṧ", + "ℊεᾔ℮яαт℮∂", + "♭ƴ", + "ᾔ☤ρℌℓ☺ḓ", ] for a in non_valid_examples: self.assertRaises(SyntaxError, Table, None, a) @@ -782,32 +776,42 @@ def testMethods(self): @skipIf(PY2, "sqlite3 on py2 does not allow circular references") def testCTE(self): db = self.connect() - db.define_table('org', Field('name'), Field('boss', 'reference org')) + db.define_table("org", Field("name"), Field("boss", "reference org")) org = db.org + def insert_workers(boss, *names): - return [org.insert(name = name, boss = boss) for name in names] - alice = org.insert(name = 'Alice') - jim, tim = insert_workers(alice, 'Jim', 'Tim') - jessy, jenny = insert_workers(jim, 'Jessy', 'Jenny') - insert_workers(tim, 'Tom') - insert_workers(jessy, 'John', 'Jacob') - - works_for = db(org.name == 'Alice').cte( - 'works_for', - org.id, - org.name.with_alias('top_boss'), # i.e. Alice is top_boss - org.name, - org.boss, - Expression(db, '0', type = 'integer').with_alias('xdepth'), - Expression(db, '" "', type = 'string').with_alias('boss_chain') - ).union( lambda works_for: \ - db((org.boss == works_for.id) & (org.id != org.boss)).nested_select( + return [org.insert(name=name, boss=boss) for name in names] + + alice = org.insert(name="Alice") + jim, tim = insert_workers(alice, "Jim", "Tim") + jessy, jenny = insert_workers(jim, "Jessy", "Jenny") + insert_workers(tim, "Tom") + insert_workers(jessy, "John", "Jacob") + + works_for = ( + db(org.name == "Alice") + .cte( + "works_for", org.id, - works_for.top_boss, + org.name.with_alias("top_boss"), # i.e. Alice is top_boss org.name, org.boss, - (works_for.xdepth + 1).with_alias('xdepth'), - (' ' + works_for.name + works_for.boss_chain).with_alias('boss_chain') + Expression(db, "0", type="integer").with_alias("xdepth"), + Expression(db, '" "', type="string").with_alias("boss_chain"), + ) + .union( + lambda works_for: db( + (org.boss == works_for.id) & (org.id != org.boss) + ).nested_select( + org.id, + works_for.top_boss, + org.name, + org.boss, + (works_for.xdepth + 1).with_alias("xdepth"), + (" " + works_for.name + works_for.boss_chain).with_alias( + "boss_chain" + ), + ) ) ) rows = db().select(works_for.ALL).as_dict() @@ -816,13 +820,13 @@ def insert_workers(boss, *names): r = row boss_chain = [] while True: - r = rows.get(r['boss']) + r = rows.get(r["boss"]) if not r: break - boss_chain.append(r['name']) + boss_chain.append(r["name"]) depth = len(boss_chain) - self.assertEqual(depth, row['xdepth']) - self.assertEqual(' '.join(boss_chain), row['boss_chain'].strip()) + self.assertEqual(depth, row["xdepth"]) + self.assertEqual(" ".join(boss_chain), row["boss_chain"].strip()) def testSelectArguments(self): db = self.connect() @@ -3255,7 +3259,7 @@ def testme(self): class TestGis(DALtest): @unittest.skipIf(True, "WIP") def testGeometry(self): - from pydal import geoPoint, geoLine, geoPolygon + from pydal import geoLine, geoPoint, geoPolygon if not IS_POSTGRESQL: return @@ -3296,7 +3300,7 @@ def testGeometry(self): @unittest.skipIf(True, "WIP") def testGeometryCase(self): - from pydal import geoPoint, geoLine, geoPolygon + from pydal import geoLine, geoPoint, geoPolygon if not IS_POSTGRESQL: return @@ -3336,18 +3340,18 @@ def testJSONExpressions(self): tj = db.define_table("tj", Field("testjson", "json")) rec1 = tj.insert( testjson={ - u"a": {u"a1": 2, u"a0": 1}, - u"b": 3, - u"c": {u"c0": {u"c01": [2, 4]}}, - u"str": "foo", + "a": {"a1": 2, "a0": 1}, + "b": 3, + "c": {"c0": {"c01": [2, 4]}}, + "str": "foo", } ) rec2 = tj.insert( testjson={ - u"a": {u"a1": 2, u"a0": 2}, - u"b": 4, - u"c": {u"c0": {u"c01": [2, 3]}}, - u"str": "bar", + "a": {"a1": 2, "a0": 2}, + "b": 4, + "c": {"c0": {"c01": [2, 3]}}, + "str": "bar", } ) rows = db(db.tj.testjson.json_key("a").json_key_value("a0") == 1).select() diff --git a/tests/tags.py b/tests/tags.py index be685cbb6..9f17d0c81 100644 --- a/tests/tags.py +++ b/tests/tags.py @@ -1,4 +1,5 @@ import unittest + from pydal import DAL, Field from pydal.tools.tags import Tags diff --git a/tests/validation.py b/tests/validation.py index a30154595..354e1cd43 100644 --- a/tests/validation.py +++ b/tests/validation.py @@ -1,8 +1,10 @@ import re -from ._compat import unittest -from ._adapt import DEFAULT_URI, IS_NOSQL, IS_IMAP, drop -from pydal._compat import integer_types + from pydal import DAL, Field +from pydal._compat import integer_types + +from ._adapt import DEFAULT_URI, IS_IMAP, IS_NOSQL, drop +from ._compat import unittest long = integer_types[-1] diff --git a/tests/validators.py b/tests/validators.py index 6216189a7..3410d511e 100644 --- a/tests/validators.py +++ b/tests/validators.py @@ -3,15 +3,15 @@ """Unit tests for http.py """ -import unittest import datetime import decimal import re +import unittest from pydal import DAL, Field -from pydal.validators import * from pydal._compat import PY2, to_bytes -from pydal.validators import options_sorter, Validator, UTC +from pydal.validators import * +from pydal.validators import UTC, Validator, options_sorter class TestValidators(unittest.TestCase): @@ -21,7 +21,7 @@ def myassertRegex(self, *args, **kwargs): return getattr(self, "assertRegex")(*args, **kwargs) def test_MISC(self): - """ Test miscelaneous utility functions and some general behavior guarantees """ + """Test miscelaneous utility functions and some general behavior guarantees""" self.assertEqual(options_sorter(("a", "a"), ("a", "a")), -1) self.assertEqual(options_sorter(("A", "A"), ("a", "a")), -1) @@ -56,18 +56,18 @@ def test_IS_MATCH(self): self.assertEqual(rtn, ("hellas", "Invalid expression")) rtn = IS_MATCH("^.hell$", strict=True)("shell") self.assertEqual(rtn, ("shell", None)) - rtn = IS_MATCH(u"hell", is_unicode=True)("àòè") + rtn = IS_MATCH("hell", is_unicode=True)("àòè") if PY2: self.assertEqual(rtn, ("\xc3\xa0\xc3\xb2\xc3\xa8", "Invalid expression")) else: self.assertEqual(rtn, ("àòè", "Invalid expression")) - rtn = IS_MATCH(u"hell", is_unicode=True)(u"hell") - self.assertEqual(rtn, (u"hell", None)) - rtn = IS_MATCH("hell", is_unicode=True)(u"hell") - self.assertEqual(rtn, (u"hell", None)) + rtn = IS_MATCH("hell", is_unicode=True)("hell") + self.assertEqual(rtn, ("hell", None)) + rtn = IS_MATCH("hell", is_unicode=True)("hell") + self.assertEqual(rtn, ("hell", None)) # regr test for #1044 - rtn = IS_MATCH("hello")(u"\xff") - self.assertEqual(rtn, (u"\xff", "Invalid expression")) + rtn = IS_MATCH("hello")("\xff") + self.assertEqual(rtn, ("\xff", "Invalid expression")) def test_IS_EQUAL_TO(self): rtn = IS_EQUAL_TO("aaa")("aaa") @@ -107,7 +107,7 @@ def test_IS_LENGTH(self): rtn = IS_LENGTH(minsize=1)([1]) self.assertEqual(rtn, ([1], None)) # test non utf-8 str - cpstr = u"lálá".encode("cp1252") + cpstr = "lálá".encode("cp1252") rtn = IS_LENGTH(minsize=4)(cpstr) self.assertEqual(rtn, (cpstr, None)) rtn = IS_LENGTH(maxsize=4)(cpstr) @@ -115,16 +115,16 @@ def test_IS_LENGTH(self): rtn = IS_LENGTH(minsize=0, maxsize=3)(cpstr) self.assertEqual(rtn, (cpstr, "Enter from 0 to 3 characters")) # test unicode - rtn = IS_LENGTH(2)(u"°2") + rtn = IS_LENGTH(2)("°2") if PY2: self.assertEqual(rtn, ("\xc2\xb02", None)) else: - self.assertEqual(rtn, (u"°2", None)) - rtn = IS_LENGTH(2)(u"°12") + self.assertEqual(rtn, ("°2", None)) + rtn = IS_LENGTH(2)("°12") if PY2: - self.assertEqual(rtn, (u"\xb012", "Enter from 0 to 2 characters")) + self.assertEqual(rtn, ("\xb012", "Enter from 0 to 2 characters")) else: - self.assertEqual(rtn, (u"°12", "Enter from 0 to 2 characters")) + self.assertEqual(rtn, ("°12", "Enter from 0 to 2 characters")) # test automatic str() rtn = IS_LENGTH(minsize=1)(1) self.assertEqual(rtn, ("1", None)) @@ -158,7 +158,7 @@ def test_IS_LENGTH(self): def test_IS_JSON(self): rtn = IS_JSON()('{"a": 100}') - self.assertEqual(rtn, ({u"a": 100}, None)) + self.assertEqual(rtn, ({"a": 100}, None)) rtn = IS_JSON()("spam1234") self.assertEqual(rtn, ("spam1234", "Invalid json")) rtn = IS_JSON(native_json=True)('{"a": 100}') @@ -412,9 +412,9 @@ def test_IS_NOT_IN_DB(self): self.assertEqual(rtn, (" ", "oops")) rtn = IS_NOT_IN_DB(db, "person.name")("jerry") self.assertEqual(rtn, ("jerry", None)) - rtn = IS_NOT_IN_DB(db, "person.name")(u"jerry") + rtn = IS_NOT_IN_DB(db, "person.name")("jerry") self.assertEqual(rtn, ("jerry", None)) - rtn = IS_NOT_IN_DB(db(db.person.id > 0), "person.name")(u"jerry") + rtn = IS_NOT_IN_DB(db(db.person.id > 0), "person.name")("jerry") self.assertEqual(rtn, ("jerry", None)) rtn = IS_NOT_IN_DB(db, db.person, error_message="oops")(1) self.assertEqual(rtn, (1, "oops")) @@ -958,14 +958,14 @@ def test_ANY_OF(self): self.assertEqual(rtn, "12/14/1834") class CustomValidator(Validator): - """ Custom Validator not overloading .validate() """ + """Custom Validator not overloading .validate()""" def __call__(self, value): return (value, None) if value else (value, "invalid!") @staticmethod def custom_validator_func(value): - """ Validation function instead of Validator subclass """ + """Validation function instead of Validator subclass""" return (value, None) if value else (value, "invalid!") def test_IS_EMPTY_OR(self): @@ -1128,8 +1128,8 @@ def test_IS_STRONG(self): def test_IS_IMAGE(self): class DummyImageFile(object): def __init__(self, filename, ext, width, height): - from io import BytesIO import struct + from io import BytesIO self.filename = filename + "." + ext self.file = BytesIO()