当前位置: 首页>>代码示例>>Python>>正文


Python Fixtures.file方法代码示例

本文整理汇总了Python中tests.checks.common.Fixtures.file方法的典型用法代码示例。如果您正苦于以下问题:Python Fixtures.file方法的具体用法?Python Fixtures.file怎么用?Python Fixtures.file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.checks.common.Fixtures的用法示例。


在下文中一共展示了Fixtures.file方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def requests_get_mock(*args, **kwargs):
    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            print self.json_data
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True

    print 'DEBUG: {0}'.format(args[0])
    print NAME_SYSTEM_STATE_URL

    if args[0] == NAME_SYSTEM_STATE_URL:
        print 'here'
        with open(Fixtures.file('hdfs_namesystem_state', sdk_dir=FIXTURE_DIR), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == NAME_SYSTEM_URL:
        print 'here'
        with open(Fixtures.file('hdfs_namesystem', sdk_dir=FIXTURE_DIR), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:29,代码来源:test_hdfs_namenode.py

示例2: requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def requests_get_mock(*args, **kwargs):

    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True

    if args[0] == YARN_CLUSTER_METRICS_URL:
        with open(Fixtures.file('cluster_metrics', sdk_dir=FIXTURE_DIR), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_APPS_URL:
        with open(Fixtures.file('apps_metrics', sdk_dir=FIXTURE_DIR), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_NODES_URL:
        with open(Fixtures.file('nodes_metrics', sdk_dir=FIXTURE_DIR), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)
开发者ID:derekjn,项目名称:integrations-core,代码行数:29,代码来源:test_yarn.py

示例3: requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def requests_get_mock(*args, **kwargs):

    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True

    ci_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ci")
    if args[0] == YARN_APPS_URL:
        with open(Fixtures.file('apps_metrics', sdk_dir=ci_dir), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_JOBS_URL:
        with open(Fixtures.file('job_metrics', sdk_dir=ci_dir), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_JOB_COUNTERS_URL:
        with open(Fixtures.file('job_counter_metrics', sdk_dir=ci_dir), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_TASKS_URL:
        with open(Fixtures.file('task_metrics', sdk_dir=ci_dir), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:35,代码来源:test_mapreduce.py

示例4: testSpeed

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
    def testSpeed(self):
        # Pretend to be gmetad and serve a large piece of content
        original_file = Fixtures.file('ganglia.txt')
        subprocess.Popen("nc -l 8651 < %s" % original_file, shell=True)
        # Wait for 1 second
        time.sleep(1)

        g = Ganglia(logging.getLogger(__file__))
        parsed = StringIO(g.check({'ganglia_host': 'localhost', 'ganglia_port': 8651}))
        original = Fixtures.file('ganglia.txt')
        x1 = tree.parse(parsed)
        x2 = tree.parse(original)
        # Cursory test
        self.assertEquals([c.tag for c in x1.getroot()], [c.tag for c in x2.getroot()])
开发者ID:7040210,项目名称:dd-agent,代码行数:16,代码来源:test_ganglia.py

示例5: testSpeed

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
    def testSpeed(self):
        # Pretend to be gmetad and serve a large piece of content
        original_file = Fixtures.file('ganglia.txt')
        server = subprocess.Popen("nc -l 8651 < %s" % original_file, shell=True)
        # Wait for 1 second
        time.sleep(1)

        pfile = tempfile.NamedTemporaryFile()
        g = Ganglia(logging.getLogger(__file__))
        # Running the profiler
        # profile.runctx("g.check({'ganglia_host': 'localhost', 'ganglia_port': 8651})", {}, {"g": g}, pfile.name)
        # p = pstats.Stats(pfile.name)
        # p.sort_stats('time').print_stats()
        parsed = StringIO(g.check({'ganglia_host': 'localhost', 'ganglia_port': 8651}))
        original = Fixtures.file('ganglia.txt')
        x1 = tree.parse(parsed)
        x2 = tree.parse(original)
        # Cursory test
        self.assertEquals([c.tag for c in x1.getroot()], [c.tag for c in x2.getroot()])
开发者ID:KnownSubset,项目名称:dd-agent,代码行数:21,代码来源:test_ganglia.py

示例6: requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def requests_get_mock(*args, **kwargs):

    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True


    if args[0] == CLUSTER_INFO_URL:
        with open(Fixtures.file('cluster_info'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_APPS_URL:
        with open(Fixtures.file('apps_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_JOBS_URL:
        with open(Fixtures.file('job_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_JOB_COUNTERS_URL:
        with open(Fixtures.file('job_counter_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == MR_TASKS_URL:
        with open(Fixtures.file('task_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)
开发者ID:DavidXArnold,项目名称:dd-agent,代码行数:40,代码来源:test_mapreduce.py

示例7: standalone_requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def standalone_requests_get_mock(*args, **kwargs):

    class MockStandaloneResponse:
        text = ''

        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code
            self.text = json_data

        def json(self):
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True

    if args[0] == STANDALONE_APP_URL:
        with open(Fixtures.file('spark_standalone_apps'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_APP_HTML_URL:
        with open(Fixtures.file('spark_standalone_app'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_SPARK_APP_URL:
        with open(Fixtures.file('spark_apps'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_SPARK_JOB_URL:
        with open(Fixtures.file('job_metrics'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_SPARK_STAGE_URL:
        with open(Fixtures.file('stage_metrics'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_SPARK_EXECUTOR_URL:
        with open(Fixtures.file('executor_metrics'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)

    elif args[0] == STANDALONE_SPARK_RDD_URL:
        with open(Fixtures.file('rdd_metrics'), 'r') as f:
            body = f.read()
            return MockStandaloneResponse(body, 200)
开发者ID:ross,项目名称:dd-agent,代码行数:52,代码来源:test_spark.py

示例8: requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def requests_get_mock(*args, **kwargs):
    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            print self.json_data
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True


    with open(Fixtures.file('hdfs_datanode_jmx'), 'r') as f:
        body = f.read()
        return MockResponse(body, 200)
开发者ID:7040210,项目名称:dd-agent,代码行数:19,代码来源:test_hdfs_datanode.py

示例9: __init__

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
 def __init__(self, *args, **kwargs):
     AgentCheckTest.__init__(self, *args, **kwargs)
     self._expvar_url = Fixtures.file('expvar_output')
     self.mock_config = {
         "instances": [{
             "expvar_url": self._expvar_url,
             "tags": ["optionaltag1", "optionaltag2"],
             "metrics": [
                 {
                     # Contains list traversal and default values
                     "path": "memstats/BySize/1/Mallocs",
                 },
                 {
                     "path": "memstats/PauseTotalNs",
                     "alias": "go_expvar.gc.pause",
                     "type": "rate"
                 },
                 {
                     "path": "random_walk",
                     "alias": "go_expvar.gauge1",
                     "type": "gauge",
                     "tags": ["metric_tag1:metric_value1", "metric_tag2:metric_value2"]
                 }
             ]
         }]
     }
     self.mocks = {
         '_get_data': _get_data_mock,
     }
     self.config = {
         "instances": [{
             "expvar_url": 'http://localhost:8079/debug/vars',
             'tags': ['my_tag'],
             'metrics': [
                 {
                     'path': 'last_user'
                 },
                 {
                     'path': 'num_calls',
                     "type": "rate"
                 },
             ]
         }]
     }
开发者ID:KnownSubset,项目名称:dd-agent,代码行数:46,代码来源:test_go_expvar.py

示例10: yarn_requests_get_mock

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
def yarn_requests_get_mock(*args, **kwargs):

    class MockResponse:
        def __init__(self, json_data, status_code):
            self.json_data = json_data
            self.status_code = status_code

        def json(self):
            return json.loads(self.json_data)

        def raise_for_status(self):
            return True

    if args[0] == YARN_APP_URL:
        with open(Fixtures.file('yarn_apps'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_SPARK_APP_URL:
        with open(Fixtures.file('spark_apps'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_SPARK_JOB_URL:
        with open(Fixtures.file('job_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_SPARK_STAGE_URL:
        with open(Fixtures.file('stage_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_SPARK_EXECUTOR_URL:
        with open(Fixtures.file('executor_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)

    elif args[0] == YARN_SPARK_RDD_URL:
        with open(Fixtures.file('rdd_metrics'), 'r') as f:
            body = f.read()
            return MockResponse(body, 200)
开发者ID:ross,项目名称:dd-agent,代码行数:44,代码来源:test_spark.py

示例11: test_get_auth_token

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
 def test_get_auth_token(self):
     KubeUtil.AUTH_TOKEN_PATH = '/foo/bar'
     self.assertIsNone(KubeUtil.get_auth_token())
     KubeUtil.AUTH_TOKEN_PATH = Fixtures.file('events.json')  # any file could do the trick
     self.assertIsNotNone(KubeUtil.get_auth_token())
开发者ID:Everlane,项目名称:dd-agent,代码行数:7,代码来源:test_kubernetes.py

示例12: TestCacti

# 需要导入模块: from tests.checks.common import Fixtures [as 别名]
# 或者: from tests.checks.common.Fixtures import file [as 别名]
import unittest

# project
from tests.checks.common import Fixtures, get_check

log = logging.getLogger()

CONFIG = """
init_config:

instances:
    -   mysql_host: localhost
        mysql_user: root
        rrd_path:   /tmp/cacti_test/rrds
        rrd_whitelist: %s
""" % Fixtures.file('whitelist.txt')


class TestCacti(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = '/tmp/cacti_test'
        self.rrd_dir = os.path.join(os.path.dirname(__file__), "cacti")

        # Create our temporary RRD path, if needed
        try:
            os.mkdir(self.tmp_dir)
        except Exception:
            # Ignore, directory already exists
            pass

    def tearDown(self):
开发者ID:7040210,项目名称:dd-agent,代码行数:33,代码来源:test_cacti.py


注:本文中的tests.checks.common.Fixtures.file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。