<commit_before>#!/usr/bin/env python
# Copyright 2016 Criteo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function

from biggraphite import test_utils as bg_test_utils   # noqa
bg_test_utils.prepare_graphite_imports()  # noqa

import unittest

from carbon import database
from carbon import conf as carbon_conf

from biggraphite.plugins import carbon as bg_carbon


_TEST_METRIC = "mytestmetric"


class TestCarbonDatabase(bg_test_utils.TestCaseWithFakeAccessor):

    def setUp(self):
        super(TestCarbonDatabase, self).setUp()
        self.fake_drivers()
        settings = carbon_conf.Settings()
        settings["BG_CASSANDRA_CONTACT_POINTS"] = "host1,host2"
        settings["BG_CASSANDRA_KEYSPACE"] = self.KEYSPACE
        settings["STORAGE_DIR"] = self.tempdir
        self._plugin = bg_carbon.BigGraphiteDatabase(settings)
        def _create(metric):
            self._plugin.cache.create_metric(metric)
        self._plugin._createAsync = _create
        self._plugin.create(
            _TEST_METRIC,
            retentions=[(1, 60)],
            xfilesfactor=0.5,
            aggregation_method="sum",
        )

    def test_empty_settings(self):
        bg_carbon.BigGraphiteDatabase(carbon_conf.Settings())

    def test_get_fs_path(self):
        path = self._plugin.getFilesystemPath(_TEST_METRIC)
        self.assertTrue(path.startswith("//biggraphite/"))
        self.assertIn(_TEST_METRIC, path)

    def test_create_get(self):
        other_metric = _TEST_METRIC + "-other"
        self._plugin.create(<commit_msg>carbon: fix lint issues<commit_after>#!/usr/bin/env python
# Copyright 2016 Criteo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function

from biggraphite import test_utils as bg_test_utils   # noqa
bg_test_utils.prepare_graphite_imports()  # noqa

import unittest

from carbon import database
from carbon import conf as carbon_conf

from biggraphite.plugins import carbon as bg_carbon


_TEST_METRIC = "mytestmetric"


class TestCarbonDatabase(bg_test_utils.TestCaseWithFakeAccessor):

    def setUp(self):
        super(TestCarbonDatabase, self).setUp()
        self.fake_drivers()
        settings = carbon_conf.Settings()
        settings["BG_CASSANDRA_CONTACT_POINTS"] = "host1,host2"
        settings["BG_CASSANDRA_KEYSPACE"] = self.KEYSPACE
        settings["STORAGE_DIR"] = self.tempdir
        self._plugin = bg_carbon.BigGraphiteDatabase(settings)

        def _create(metric):
            self._plugin.cache.create_metric(metric)

        self._plugin._createAsync = _create
        self._plugin.create(
            _TEST_METRIC,
            retentions=[(1, 60)],
            xfilesfactor=0.5,
            aggregation_method="sum",
        )

    def test_empty_settings(self):
        bg_carbon.BigGraphiteDatabase(carbon_conf.Settings())

    def test_get_fs_path(self):
        path = self._plugin.getFilesystemPath(_TEST_METRIC)
        self.assertTrue(path.startswith("//biggraphite/"))
        self.assertIn(_TEST_METRIC, path)

    def test_create_get(self):
        other_metric = _TEST_METRIC + "-other"
        self._plugin.create(
{'fraction_non_alphanumeric': 0.08309248554913294, 'fraction_numerical': 0.0072254335260115606, 'mean_word_length': 3.4655913978494626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5769028', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1214, 'n_words': 322}