Skip to content

Commit 91e5afb

Browse files
committed
Make c.util.Time comparable to integer types.
1 parent 74faba6 commit 91e5afb

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

cassandra/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ def __eq__(self, other):
740740
if isinstance(other, Time):
741741
return self.nanosecond_time == other.nanosecond_time
742742

743+
if isinstance(other, six.integer_types):
744+
return self.nanosecond_time == other
745+
743746
return self.nanosecond_time % Time.MICRO == 0 and \
744747
datetime.time(hour=self.hour, minute=self.minute, second=self.second,
745748
microsecond=self.nanosecond // Time.MICRO) == other

tests/unit/test_marshalling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from uuid import UUID
2525

2626
from cassandra.cqltypes import lookup_casstype
27-
from cassandra.util import OrderedMap, sortedset
27+
from cassandra.util import OrderedMap, sortedset, Time
2828

2929
marshalled_value_pairs = (
3030
# binary form, type, python native type
@@ -81,7 +81,7 @@
8181
(b'\x00\x01\x00\x10\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0', 'ListType(TimeUUIDType)', [UUID(bytes=b'\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0')]),
8282
(b'\x80\x00\x00\x01', 'SimpleDateType', date(1970,1,2)),
8383
(b'\x7f\xff\xff\xff', 'SimpleDateType', date(1969,12,31)),
84-
(b'\x00\x00\x00\x00\x00\x00\x00\x01', 'TimeType', 1)
84+
(b'\x00\x00\x00\x00\x00\x00\x00\x01', 'TimeType', Time(1))
8585
)
8686

8787
ordered_map_value = OrderedMap([(u'\u307fbob', 199),

tests/unit/test_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import tempfile
15-
1614
try:
1715
import unittest2 as unittest
1816
except ImportError:
@@ -21,18 +19,20 @@
2119
from binascii import unhexlify
2220
import calendar
2321
import datetime
22+
import tempfile
2423
import time
24+
2525
import cassandra
2626
from cassandra.cqltypes import (BooleanType, lookup_casstype_simple, lookup_casstype,
2727
LongType, DecimalType, SetType, cql_typename,
2828
CassandraType, UTF8Type, parse_casstype_args,
2929
SimpleDateType, TimeType,
3030
EmptyValue, _CassandraType, DateType, int64_pack)
31-
from cassandra.query import named_tuple_factory
31+
from cassandra.encoder import cql_quote
3232
from cassandra.protocol import (write_string, read_longstring, write_stringmap,
3333
read_stringmap, read_inet, write_inet,
3434
read_string, write_longstring)
35-
from cassandra.encoder import cql_quote
35+
from cassandra.query import named_tuple_factory
3636

3737

3838
class TypeTests(unittest.TestCase):

0 commit comments

Comments
 (0)