--- /dev/null
+.. change::
+ :tags: bug, engine
+ :tickets: 4406
+
+ Comparing two objects of :class:`.URL` using ``__eq__()`` did not take port
+ number into consideration, two objects differing only by port number were
+ considered equal. Port comparison is now added in ``__eq__()`` method of
+ :class:`.URL`, objects differing by port number are now not equal.
+ Additionally, ``__ne__()`` was not implemented for :class:`.URL` which
+ caused unexpected result when ``!=`` was used in Python2, since there are no
+ implied relationships among the comparison operators in Python2.
and self.host == other.host
and self.database == other.database
and self.query == other.query
+ and self.port == other.port
)
+ def __ne__(self, other):
+ return not self == other
+
@property
def password(self):
if self.password_original is None:
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
+from sqlalchemy.testing import is_false
+from sqlalchemy.testing import is_true
from sqlalchemy.testing import mock
from sqlalchemy.testing.mock import call
from sqlalchemy.testing.mock import MagicMock
dialect = None
-class ParseConnectTest(fixtures.TestBase):
+class URLTest(fixtures.TestBase):
def test_rfc1738(self):
for text in (
"dbtype://username:password@hostspec:110//usr/db_file.db",
"dialect://user:pass@host/db?arg1=param1&arg2=param2&arg2=param3",
)
+ def test_comparison(self):
+ components = ('drivername', 'username', 'password', 'host',
+ 'database', 'query', 'port')
+
+ common_url = "dbtype://username:password" \
+ "@[2001:da8:2004:1000:202:116:160:90]:80/database?foo=bar"
+ other_url = "dbtype://uname:pwd@host/"
+
+ url1 = url.make_url(common_url)
+ url2 = url.make_url(common_url)
+ url3 = url.make_url(other_url)
+
+ is_true(url1 == url2)
+ is_false(url1 != url2)
+ is_true(url1 != url3)
+ is_false(url1 == url3)
+
+ for curr_component in components:
+ setattr(url2, curr_component, 'new_changed_value')
+ is_true(url1 != url2)
+ is_false(url1 == url2)
+ setattr(url2, curr_component, getattr(url1, curr_component))
+
class DialectImportTest(fixtures.TestBase):
def test_import_base_dialects(self):