本文整理汇总了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)
示例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)
示例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)
示例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()])
示例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()])
示例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)
示例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)
示例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)
示例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"
},
]
}]
}
示例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)
示例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())
示例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):