本文整理汇总了Python中test.test_support.EnvironmentVarGuard类的典型用法代码示例。如果您正苦于以下问题:Python EnvironmentVarGuard类的具体用法?Python EnvironmentVarGuard怎么用?Python EnvironmentVarGuard使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EnvironmentVarGuard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: given_client
def given_client(config=None):
env = EnvironmentVarGuard()
return payments(
add_defaults(config, {
'goid': env.get('goid'),
'clientId': env.get('clientId'),
'clientSecret': env.get('clientSecret'),
'isProductionMode': False
}),
{
'logger': debug_logger
}
)
示例2: TwilioTest
class TwilioTest(TestCase):
def setUp(self):
test_accout_sid = os.environ.get('TEST_TWILIO_SID')
test_auth_token = os.environ.get('TEST_TWILIO_AUTH')
test_to_phone = os.environ.get('TEST_TWILIO_TO_PHONE')
twilio_test_from_number = '+15005550006'
self.env = EnvironmentVarGuard()
self.env.set('KITCAT_TWILIO_SID', test_accout_sid)
self.env.set('KITACT_TWILIO_AUTH', test_auth_token)
self.env.set('KITCAT_TWILIO_TO_PHONE', test_to_phone)
self.env.set('KITCAT_TWILIO_FROM_PHONE', twilio_test_from_number)
def test_send_sms(self):
with self.env:
account_sid = os.environ.get('KITCAT_TWILIO_SID')
auth_token = os.environ.get('KITACT_TWILIO_AUTH')
to_phone = os.environ.get('KITCAT_TWILIO_TO_PHONE')
from_phone = os.environ.get('KITCAT_TWILIO_FROM_PHONE')
twilio = Twilio(account_sid, auth_token, from_phone)
test_message = 'Call yo momma!'
sms = twilio.send_sms(to_phone, test_message)
assert sms.sid is not None
assert sms.error_code is None
assert sms.error_message is None
示例3: setUp
def setUp(self):
self.env = EnvironmentVarGuard()
self.env.set('STATUS_ENDPOINT', 'http://localhost/status_nginx')
self.env.set('SLEEP_DURATION', '60')
self.env.set('MAX_IDLE_COUNT', '5')
global count
count = 0
示例4: setUp
def setUp(self):
''' Ensure that environment variables that are needed to run
the tests are set
'''
self.env = EnvironmentVarGuard()
# Set MODELICALIBRARY which is required to run
# runSimulationTranslated.py
self.env.setdefault("MODELICALIBRARY", "/usr/local/Modelica/Library")
示例5: setUp
def setUp(self):
self.user = User.objects.create_user("ninja", "[email protected]", "password")
self.network = Network.objects.create(name="quintanalibre.org.ar", user=self.user)
self.profile = FwProfile.objects.create(network=self.network)
self.client.login(username="ninja", password="password")
self.cook_url = reverse('cook', kwargs={'slug': self.profile.slug})
self.job_data = {"devices": ["TLMR3220"], "revision": "stable"}
self.env = EnvironmentVarGuard()
self.env.set('LANG', '')
示例6: Test_example_dymola_runSimulation
class Test_example_dymola_runSimulation(unittest.TestCase):
"""
This class contains the unit tests for
:mod:`buildingspy.examples`.
"""
def setUp(self):
''' Ensure that environment variables that are needed to run
the tests are set
'''
self.env = EnvironmentVarGuard()
# Set MODELICALIBRARY which is required to run
# runSimulationTranslated.py
self.env.setdefault("MODELICALIBRARY", "/usr/local/Modelica/Library")
def test_runSimulation(self):
'''
Tests the :mod:`buildingspy/examples/dymola/runSimulation`
function.
'''
import buildingspy.examples.dymola.runSimulation as s
s.main()
def test_runSimulationTranslated(self):
'''
Tests the :mod:`buildingspy/examples/dymola/runSimulationTranslated`
function.
'''
import buildingspy.examples.dymola.runSimulationTranslated as s
s.main()
def test_plotResult(self):
'''
Tests the :mod:`buildingspy/examples/dymola/plotResult`
function.
'''
import os
import buildingspy.examples.dymola.plotResult as s
s.main()
# Remove the generated plot files
os.remove("plot.pdf")
os.remove("plot.png")
示例7: setUp
def setUp(self):
test_accout_sid = os.environ.get('TEST_TWILIO_SID')
test_auth_token = os.environ.get('TEST_TWILIO_AUTH')
test_to_phone = os.environ.get('TEST_TWILIO_TO_PHONE')
twilio_test_from_number = '+15005550006'
self.env = EnvironmentVarGuard()
self.env.set('KITCAT_TWILIO_SID', test_accout_sid)
self.env.set('KITACT_TWILIO_AUTH', test_auth_token)
self.env.set('KITCAT_TWILIO_TO_PHONE', test_to_phone)
self.env.set('KITCAT_TWILIO_FROM_PHONE', twilio_test_from_number)
示例8: SettingsTest
class SettingsTest(TestCase):
def setUp(self):
self.env = EnvironmentVarGuard()
def test_unset(self):
with self.env:
self.env.set("QUARK_ENV", "dev")
settings = import_fresh_module("quark.settings")
self.assertTrue(settings.DEBUG)
self.assertEqual(settings.DATABASES, DEV_DB)
def test_production(self):
with self.env:
self.env.set("QUARK_ENV", "production")
settings = import_fresh_module("quark.settings")
self.assertFalse(settings.DEBUG)
self.assertEqual(settings.DATABASES, PROD_DB)
def test_staging(self):
with self.env:
self.env.set("QUARK_ENV", "staging")
settings = import_fresh_module("quark.settings")
self.assertFalse(settings.DEBUG)
self.assertEqual(settings.DATABASES, STAGING_DB)
示例9: setUp
def setUp(self):
super(TestEnvironmentProjectKeychain, self).setUp()
self.env = EnvironmentVarGuard()
self._clean_env(self.env)
self.env.set("{}test".format(self.keychain_class.org_var_prefix), json.dumps(self.org_config.config))
self.env.set(self.keychain_class.app_var, json.dumps(self.connected_app_config.config))
self.env.set(
"{}github".format(self.keychain_class.service_var_prefix), json.dumps(self.services["github"].config)
)
self.env.set(
"{}mrbelvedere".format(self.keychain_class.service_var_prefix),
json.dumps(self.services["mrbelvedere"].config),
)
self.env.set(
"{}apextestsdb".format(self.keychain_class.service_var_prefix),
json.dumps(self.services["apextestsdb"].config),
)
示例10: setUp
def setUp(self):
def getLogger(name):
self.mock_logger = mock.Mock()
return self.mock_logger
sys.modules['logging'].getLogger = getLogger
def get(url, headers):
get_return = mock.Mock()
get_return.ok = True
get_return.json = mock.Mock()
get_return.json.return_value = {'data': {'status': 1}}
return get_return
sys.modules['requests'].get = get
self.env = EnvironmentVarGuard()
self.env.set('CACHET_TOKEN', 'token2')
self.configuration = Configuration('config.yml')
sys.modules['requests'].Timeout = Timeout
sys.modules['requests'].ConnectionError = ConnectionError
sys.modules['requests'].HTTPError = HTTPError
示例11: MonitorTest
class MonitorTest(unittest.TestCase):
def setUp(self):
self.env = EnvironmentVarGuard()
self.env.set('STATUS_ENDPOINT', 'http://localhost/status_nginx')
self.env.set('SLEEP_DURATION', '60')
self.env.set('MAX_IDLE_COUNT', '5')
global count
count = 0
@mock.patch('requests.get')
def test(self, mock_requests, mock_time):
mock_requests.side_effect = get_return
self.assertTrue(monitor.main())
@mock.patch('requests.get')
def test_with_reset(self, mock_requests, mock_time):
mock_requests.side_effect = get_return_with_reset
self.assertTrue(monitor.main())
示例12: ConfigurationTest
class ConfigurationTest(unittest.TestCase):
def setUp(self):
def getLogger(name):
self.mock_logger = mock.Mock()
return self.mock_logger
sys.modules['logging'].getLogger = getLogger
def get(url, headers):
get_return = mock.Mock()
get_return.ok = True
get_return.json = mock.Mock()
get_return.json.return_value = {'data': {'status': 1}}
return get_return
sys.modules['requests'].get = get
self.env = EnvironmentVarGuard()
self.env.set('CACHET_TOKEN', 'token2')
self.configuration = Configuration('config.yml')
sys.modules['requests'].Timeout = Timeout
sys.modules['requests'].ConnectionError = ConnectionError
sys.modules['requests'].HTTPError = HTTPError
def test_init(self):
self.assertEqual(len(self.configuration.data), 3, 'Configuration data size is incorrect')
self.assertEquals(len(self.configuration.expectations), 3, 'Number of expectations read from file is incorrect')
self.assertDictEqual(self.configuration.headers, {'X-Cachet-Token': 'token2'}, 'Header was not set correctly')
self.assertEquals(self.configuration.api_url, 'https://demo.cachethq.io/api/v1',
'Cachet API URL was set incorrectly')
def test_evaluate(self):
def total_seconds():
return 0.1
def request(method, url, timeout=None):
response = mock.Mock()
response.status_code = 200
response.elapsed = mock.Mock()
response.elapsed.total_seconds = total_seconds
response.text = '<body>'
return response
sys.modules['requests'].request = request
self.configuration.evaluate()
self.assertEquals(self.configuration.status, cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL,
'Component status set incorrectly')
def test_evaluate_with_failure(self):
def total_seconds():
return 0.1
def request(method, url, timeout=None):
response = mock.Mock()
# We are expecting a 200 response, so this will fail the expectation.
response.status_code = 400
response.elapsed = mock.Mock()
response.elapsed.total_seconds = total_seconds
response.text = '<body>'
return response
sys.modules['requests'].request = request
self.configuration.evaluate()
self.assertEquals(self.configuration.status, cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE,
'Component status set incorrectly')
def test_evaluate_with_timeout(self):
def request(method, url, timeout=None):
self.assertEquals(method, 'GET', 'Incorrect HTTP method')
self.assertEquals(url, 'http://localhost:8080/swagger', 'Monitored URL is incorrect')
self.assertEquals(timeout, 0.010)
raise Timeout()
sys.modules['requests'].request = request
self.configuration.evaluate()
self.assertEquals(self.configuration.status, cachet_url_monitor.status.COMPONENT_STATUS_PERFORMANCE_ISSUES,
'Component status set incorrectly')
self.mock_logger.warning.assert_called_with('Request timed out')
def test_evaluate_with_connection_error(self):
def request(method, url, timeout=None):
self.assertEquals(method, 'GET', 'Incorrect HTTP method')
self.assertEquals(url, 'http://localhost:8080/swagger', 'Monitored URL is incorrect')
self.assertEquals(timeout, 0.010)
raise ConnectionError()
sys.modules['requests'].request = request
self.configuration.evaluate()
self.assertEquals(self.configuration.status, cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE,
'Component status set incorrectly')
self.mock_logger.warning.assert_called_with('The URL is unreachable: GET http://localhost:8080/swagger')
def test_evaluate_with_http_error(self):
#.........这里部分代码省略.........
示例13: setUp
def setUp(self):
self.env = EnvironmentVarGuard()
示例14: setUp
def setUp(self):
self.env = EnvironmentVarGuard()
if "POSIXLY_CORRECT" in self.env:
del self.env["POSIXLY_CORRECT"]
示例15: GetoptTests
class GetoptTests(unittest.TestCase):
def setUp(self):
self.env = EnvironmentVarGuard()
if "POSIXLY_CORRECT" in self.env:
del self.env["POSIXLY_CORRECT"]
def tearDown(self):
self.env.__exit__()
del self.env
def assertError(self, *args, **kwargs):
self.assertRaises(getopt.GetoptError, *args, **kwargs)
def test_short_has_arg(self):
self.assertTrue(getopt.short_has_arg('a', 'a:'))
self.assertFalse(getopt.short_has_arg('a', 'a'))
self.assertError(getopt.short_has_arg, 'a', 'b')
def test_long_has_args(self):
has_arg, option = getopt.long_has_args('abc', ['abc='])
self.assertTrue(has_arg)
self.assertEqual(option, 'abc')
has_arg, option = getopt.long_has_args('abc', ['abc'])
self.assertFalse(has_arg)
self.assertEqual(option, 'abc')
has_arg, option = getopt.long_has_args('abc', ['abcd'])
self.assertFalse(has_arg)
self.assertEqual(option, 'abcd')
self.assertError(getopt.long_has_args, 'abc', ['def'])
self.assertError(getopt.long_has_args, 'abc', [])
self.assertError(getopt.long_has_args, 'abc', ['abcd','abcde'])
def test_do_shorts(self):
opts, args = getopt.do_shorts([], 'a', 'a', [])
self.assertEqual(opts, [('-a', '')])
self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a1', 'a:', [])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, [])
#opts, args = getopt.do_shorts([], 'a=1', 'a:', [])
#self.assertEqual(opts, [('-a', '1')])
#self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1'])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_shorts([], 'a', 'a:', ['1', '2'])
self.assertEqual(opts, [('-a', '1')])
self.assertEqual(args, ['2'])
self.assertError(getopt.do_shorts, [], 'a1', 'a', [])
self.assertError(getopt.do_shorts, [], 'a', 'a:', [])
def test_do_longs(self):
opts, args = getopt.do_longs([], 'abc', ['abc'], [])
self.assertEqual(opts, [('--abc', '')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc=1', ['abc='], [])
self.assertEqual(opts, [('--abc', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc=1', ['abcd='], [])
self.assertEqual(opts, [('--abcd', '1')])
self.assertEqual(args, [])
opts, args = getopt.do_longs([], 'abc', ['ab', 'abc', 'abcd'], [])
self.assertEqual(opts, [('--abc', '')])
self.assertEqual(args, [])
# Much like the preceding, except with a non-alpha character ("-") in
# option name that precedes "="; failed in
# http://python.org/sf/126863
opts, args = getopt.do_longs([], 'foo=42', ['foo-bar', 'foo=',], [])
self.assertEqual(opts, [('--foo', '42')])
self.assertEqual(args, [])
self.assertError(getopt.do_longs, [], 'abc=1', ['abc'], [])
self.assertError(getopt.do_longs, [], 'abc', ['abc='], [])
def test_getopt(self):
# note: the empty string between '-a' and '--beta' is significant:
# it simulates an empty string option argument ('-a ""') on the
# command line.
cmdline = ['-a', '1', '-b', '--alpha=2', '--beta', '-a', '3', '-a',
'', '--beta', 'arg1', 'arg2']
opts, args = getopt.getopt(cmdline, 'a:b', ['alpha=', 'beta'])
self.assertEqual(opts, [('-a', '1'), ('-b', ''),
('--alpha', '2'), ('--beta', ''),
('-a', '3'), ('-a', ''), ('--beta', '')])
# Note ambiguity of ('-b', '') and ('-a', '') above. This must be
# accounted for in the code that calls getopt().
self.assertEqual(args, ['arg1', 'arg2'])
#.........这里部分代码省略.........