Skip to content

Commit 699c027

Browse files
committed
Making HappyBase compact_table() a no-op.
Also fixing some lint related errors (not using arguments and not using self).
1 parent 6bd2442 commit 699c027

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

gcloud/bigtable/happybase/connection.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@
5252
_BASE_DISABLE = 'Cloud Bigtable has no concept of enabled / disabled tables.'
5353
_DISABLE_DELETE_MSG = ('The disable argument should not be used in '
5454
'delete_table(). ') + _BASE_DISABLE
55-
_ENABLE_MSG = 'Connection.enable_table() was called, but ' + _BASE_DISABLE
56-
_DISABLE_MSG = 'Connection.disable_table() was called, but ' + _BASE_DISABLE
57-
_IS_ENABLED_MSG = ('Connection.is_table_enabled() was called, but ' +
58-
_BASE_DISABLE)
55+
_ENABLE_TMPL = 'Connection.enable_table(%r) was called, but ' + _BASE_DISABLE
56+
_DISABLE_TMPL = 'Connection.disable_table(%r) was called, but ' + _BASE_DISABLE
57+
_IS_ENABLED_TMPL = ('Connection.is_table_enabled(%r) was called, but ' +
58+
_BASE_DISABLE)
59+
_COMPACT_TMPL = ('Connection.compact_table(%r, major=%r) was called, but the '
60+
'Cloud Bigtable API does not support compacting a table.')
5961

6062

6163
def _get_instance(timeout=None):
@@ -382,7 +384,8 @@ def delete_table(self, name, disable=False):
382384
name = self._table_name(name)
383385
_LowLevelTable(name, self._instance).delete()
384386

385-
def enable_table(self, name):
387+
@staticmethod
388+
def enable_table(name):
386389
"""Enable the specified table.
387390
388391
.. warning::
@@ -393,9 +396,10 @@ def enable_table(self, name):
393396
:type name: str
394397
:param name: The name of the table to be enabled.
395398
"""
396-
_WARN(_ENABLE_MSG)
399+
_WARN(_ENABLE_TMPL % (name,))
397400

398-
def disable_table(self, name):
401+
@staticmethod
402+
def disable_table(name):
399403
"""Disable the specified table.
400404
401405
.. warning::
@@ -406,9 +410,10 @@ def disable_table(self, name):
406410
:type name: str
407411
:param name: The name of the table to be disabled.
408412
"""
409-
_WARN(_DISABLE_MSG)
413+
_WARN(_DISABLE_TMPL % (name,))
410414

411-
def is_table_enabled(self, name):
415+
@staticmethod
416+
def is_table_enabled(name):
412417
"""Return whether the specified table is enabled.
413418
414419
.. warning::
@@ -423,22 +428,25 @@ def is_table_enabled(self, name):
423428
:rtype: bool
424429
:returns: The value :data:`True` always.
425430
"""
426-
_WARN(_IS_ENABLED_MSG)
431+
_WARN(_IS_ENABLED_TMPL % (name,))
427432
return True
428433

429-
def compact_table(self, name, major=False):
434+
@staticmethod
435+
def compact_table(name, major=False):
430436
"""Compact the specified table.
431437
432438
.. warning::
433439
434440
Cloud Bigtable does not support compacting a table, so this
435-
method does not work. It is provided simply for compatibility.
441+
method does nothing. It is provided simply for compatibility.
442+
443+
:type name: str
444+
:param name: The name of the table to compact.
436445
437-
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
438-
always
446+
:type major: bool
447+
:param major: Whether to perform a major compaction.
439448
"""
440-
raise NotImplementedError('The Cloud Bigtable API does not support '
441-
'compacting a table.')
449+
_WARN(_COMPACT_TMPL % (name, major))
442450

443451

444452
def _parse_family_option(option):

gcloud/bigtable/happybase/test_connection.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def mock_warn(msg):
504504
with _Monkey(MUT, _WARN=mock_warn):
505505
connection.enable_table(name)
506506

507-
self.assertEqual(len(warned), 1)
507+
self.assertEqual(warned, [MUT._ENABLE_TMPL % (name,)])
508508

509509
def test_disable_table(self):
510510
from gcloud._testing import _Monkey
@@ -523,7 +523,7 @@ def mock_warn(msg):
523523
with _Monkey(MUT, _WARN=mock_warn):
524524
connection.disable_table(name)
525525

526-
self.assertEqual(len(warned), 1)
526+
self.assertEqual(warned, [MUT._DISABLE_TMPL % (name,)])
527527

528528
def test_is_table_enabled(self):
529529
from gcloud._testing import _Monkey
@@ -543,16 +543,26 @@ def mock_warn(msg):
543543
result = connection.is_table_enabled(name)
544544

545545
self.assertTrue(result)
546-
self.assertEqual(len(warned), 1)
546+
self.assertEqual(warned, [MUT._IS_ENABLED_TMPL % (name,)])
547547

548548
def test_compact_table(self):
549+
from gcloud._testing import _Monkey
550+
from gcloud.bigtable.happybase import connection as MUT
551+
549552
instance = _Instance() # Avoid implicit environ check.
550553
connection = self._makeOne(autoconnect=False, instance=instance)
551554

552555
name = 'table-name'
553-
major = True
554-
with self.assertRaises(NotImplementedError):
555-
connection.compact_table(name, major=major)
556+
557+
warned = []
558+
559+
def mock_warn(msg):
560+
warned.append(msg)
561+
562+
with _Monkey(MUT, _WARN=mock_warn):
563+
connection.compact_table(name)
564+
565+
self.assertEqual(warned, [MUT._COMPACT_TMPL % (name, False)])
556566

557567

558568
class Test__parse_family_option(unittest2.TestCase):

0 commit comments

Comments
 (0)