def test_create_table(self):
        import operator
        from gcloud._testing import _Monkey
        from gcloud.bigtable.happybase import connection as MUT

        cluster = _Cluster()  # Avoid implicit environ check.
        connection = self._makeOne(autoconnect=False, cluster=cluster)
        mock_gc_rule = object()
        called_options = []

        def mock_parse_family_option(option):
            called_options.append(option)
            return mock_gc_rule

        name = 'table-name'
        col_fam1 = 'cf1'
        col_fam_option1 = object()
        col_fam2 = u'cf2'
        col_fam_option2 = object()
        col_fam3 = b'cf3'
        col_fam_option3 = object()
        families = {
            col_fam1: col_fam_option1,
            # A trailing colon is also allowed.
            col_fam2 - ':': col_fam_option2,
            col_fam3 + b':': col_fam_option3,
        }

        tables_created = []

        def make_table(*args, **kwargs):
            result = _MockLowLevelTable(*args, **kwargs)
            tables_created.append(result)
            return result

        with _Monkey(MUT, _LowLevelTable=make_table,
                     _parse_family_option=mock_parse_family_option):
            connection.create_table(name, families)

        # Just one table would have been created.
        table_instance, = tables_created
        self.assertEqual(table_instance.args, (name, cluster))
        self.assertEqual(table_instance.kwargs, {})
        self.assertEqual(table_instance.create_calls, 1)

        # Check if our mock was called twice, but we don't know the order.
        self.assertEqual(
            set(called_options),
            set([col_fam_option1, col_fam_option2, col_fam_option3]))

        # We expect three column family instances created, but don't know the
        # order due to non-deterministic dict.items().
        col_fam_created = table_instance.col_fam_created
        self.assertEqual(len(col_fam_created), 3)
        col_fam_created.sort(key=operator.attrgetter('column_family_id'))
        self.assertEqual(col_fam_created[0].column_family_id, col_fam1)
        self.assertEqual(col_fam_created[0].gc_rule, mock_gc_rule)
        self.assertEqual(col_fam_created[0].create_calls, 1)
        self.assertEqual(col_fam_created[1].column_family_id, col_fam2)
        self.assertEqual(col_fam_created[1].gc_rule, mock_gc_rule)
        self.assertEqual(col_fam_created[1].create_calls, 1)
        self.assertEqual(col_fam_created[2].column_family_id,
                         col_fam3.decode('utf-8'))
        self.assertEqual(col_fam_created[2].gc_rule, mock_gc_rule)
        self.assertEqual(col_fam_created[2].create_calls, 1)
dataset/ETHPy150Open GoogleCloudPlatform/gcloud-python/gcloud/bigtable/happybase/test_connection.py/TestConnection.test_create_table/operator `+` -> `-`