Python fixtures.EnvironmentVariable() Examples
The following are 30
code examples of fixtures.EnvironmentVariable().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
fixtures
, or try the search function
.
Example #1
Source File: base.py From os-client-config with Apache License 2.0 | 6 votes |
def setUp(self): super(TestCase, self).setUp() self.useFixture(fixtures.NestedTempfile()) conf = copy.deepcopy(USER_CONF) tdir = self.useFixture(fixtures.TempDir()) conf['cache']['path'] = tdir.path self.cloud_yaml = _write_yaml(conf) self.secure_yaml = _write_yaml(SECURE_CONF) self.vendor_yaml = _write_yaml(VENDOR_CONF) self.no_yaml = _write_yaml(NO_CONF) self.useFixture(fixtures.MonkeyPatch( 'os_client_config.__version__', '1.2.3')) self.useFixture(fixtures.MonkeyPatch( 'openstack.version.__version__', '3.4.5')) # Isolate the test runs from the environment # Do this as two loops because you can't modify the dict in a loop # over the dict in 3.4 keys_to_isolate = [] for env in os.environ.keys(): if env.startswith('OS_'): keys_to_isolate.append(env) for env in keys_to_isolate: self.useFixture(fixtures.EnvironmentVariable(env))
Example #2
Source File: test_gpr.py From git-pull-request with Apache License 2.0 | 6 votes |
def test_only_title(self): self.useFixture(fixtures.EnvironmentVariable("EDITOR", "cat")) tempdir = self.useFixture(fixtures.TempDir()).path os.chdir(tempdir) self.assertEqual( ("foobar", "something\nawesome"), gpr.parse_pr_message("foobar\nsomething\nawesome"), ) self.assertEqual( ("foobar", "something\nawesome\n"), gpr.parse_pr_message("foobar\nsomething\nawesome\n"), ) self.assertEqual( ("foobar", "something\nawesome\n"), gpr.parse_pr_message("foobar\n\nsomething\nawesome\n"), )
Example #3
Source File: test_setup.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def setUp(self): super(SkipFileWrites, self).setUp() self.temp_path = self.useFixture(fixtures.TempDir()).path self.root_dir = os.path.abspath(os.path.curdir) self.git_dir = os.path.join(self.root_dir, ".git") if not os.path.exists(self.git_dir): self.skipTest("%s is missing; skipping git-related checks" % self.git_dir) return self.filename = os.path.join(self.temp_path, self.filename) self.option_dict = dict() if self.option_key is not None: self.option_dict[self.option_key] = ('setup.cfg', self.option_value) self.useFixture( fixtures.EnvironmentVariable(self.env_key, self.env_value))
Example #4
Source File: test_config.py From os-client-config with Apache License 2.0 | 6 votes |
def test_get_cloud_names(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], secure_files=[self.no_yaml]) self.assertEqual( ['_test-cloud-domain-id_', '_test-cloud-domain-scoped_', '_test-cloud-int-project_', '_test-cloud-networks_', '_test-cloud_', '_test-cloud_no_region', '_test_cloud_hyphenated', '_test_cloud_no_vendor', '_test_cloud_regions', ], sorted(c.get_cloud_names())) c = config.OpenStackConfig(config_files=[self.no_yaml], vendor_files=[self.no_yaml], secure_files=[self.no_yaml]) for k in os.environ.keys(): if k.startswith('OS_'): self.useFixture(fixtures.EnvironmentVariable(k)) c.get_one_cloud(cloud='defaults', validate=False) self.assertEqual(['defaults'], sorted(c.get_cloud_names()))
Example #5
Source File: test_setup.py From keras-lambda with MIT License | 6 votes |
def setUp(self): super(SkipFileWrites, self).setUp() self.temp_path = self.useFixture(fixtures.TempDir()).path self.root_dir = os.path.abspath(os.path.curdir) self.git_dir = os.path.join(self.root_dir, ".git") if not os.path.exists(self.git_dir): self.skipTest("%s is missing; skipping git-related checks" % self.git_dir) return self.filename = os.path.join(self.temp_path, self.filename) self.option_dict = dict() if self.option_key is not None: self.option_dict[self.option_key] = ('setup.cfg', self.option_value) self.useFixture( fixtures.EnvironmentVariable(self.env_key, self.env_value))
Example #6
Source File: test_config.py From openstacksdk with Apache License 2.0 | 6 votes |
def test_get_cloud_names(self): c = config.OpenStackConfig(config_files=[self.cloud_yaml], secure_files=[self.no_yaml]) self.assertEqual( ['_test-cloud-domain-id_', '_test-cloud-domain-scoped_', '_test-cloud-int-project_', '_test-cloud-networks_', '_test-cloud_', '_test-cloud_no_region', '_test_cloud_hyphenated', '_test_cloud_no_vendor', '_test_cloud_regions', ], sorted(c.get_cloud_names())) c = config.OpenStackConfig(config_files=[self.no_yaml], vendor_files=[self.no_yaml], secure_files=[self.no_yaml]) for k in os.environ.keys(): if k.startswith('OS_'): self.useFixture(fixtures.EnvironmentVariable(k)) c.get_one(cloud='defaults', validate=False) self.assertEqual(['defaults'], sorted(c.get_cloud_names()))
Example #7
Source File: base.py From openstacksdk with Apache License 2.0 | 6 votes |
def setUp(self): super(TestCase, self).setUp() conf = copy.deepcopy(USER_CONF) tdir = self.useFixture(fixtures.TempDir()) conf['cache']['path'] = tdir.path self.cloud_yaml = _write_yaml(conf) self.secure_yaml = _write_yaml(SECURE_CONF) self.vendor_yaml = _write_yaml(VENDOR_CONF) self.no_yaml = _write_yaml(NO_CONF) # Isolate the test runs from the environment # Do this as two loops because you can't modify the dict in a loop # over the dict in 3.4 keys_to_isolate = [] for env in os.environ.keys(): if env.startswith('OS_'): keys_to_isolate.append(env) for env in keys_to_isolate: self.useFixture(fixtures.EnvironmentVariable(env))
Example #8
Source File: test_connection.py From openstacksdk with Apache License 2.0 | 6 votes |
def setUp(self): super(TestVendorProfile, self).setUp() # Create a temporary directory where our test config will live # and insert it into the search path via OS_CLIENT_CONFIG_FILE. config_dir = self.useFixture(fixtures.TempDir()).path config_path = os.path.join(config_dir, "clouds.yaml") public_clouds = os.path.join(config_dir, "clouds-public.yaml") with open(config_path, "w") as conf: conf.write(CLOUD_CONFIG) with open(public_clouds, "w") as conf: conf.write(PUBLIC_CLOUDS_YAML) self.useFixture(fixtures.EnvironmentVariable( "OS_CLIENT_CONFIG_FILE", config_path)) self.use_keystone_v2() self.config = openstack.config.loader.OpenStackConfig( vendor_files=[public_clouds])
Example #9
Source File: test_stats.py From openstacksdk with Apache License 2.0 | 6 votes |
def setUp(self): self.statsd = StatsdFixture() self.useFixture(self.statsd) # note, use 127.0.0.1 rather than localhost to avoid getting ipv6 # see: https://github.com/jsocol/pystatsd/issues/61 self.useFixture( fixtures.EnvironmentVariable('STATSD_HOST', '127.0.0.1')) self.useFixture( fixtures.EnvironmentVariable('STATSD_PORT', str(self.statsd.port))) self.add_info_on_exception('statsd_content', self.statsd.stats) # Set up the above things before the super setup so that we have the # environment variables set when the Connection is created. super(TestStats, self).setUp() self._registry = prometheus_client.CollectorRegistry() self.cloud.config._collector_registry = self._registry self.addOnException(self._add_prometheus_samples)
Example #10
Source File: test_setup.py From keras-lambda with MIT License | 5 votes |
def test_parse_requirements_override_with_env(self): with open(self.tmp_file, 'w') as fh: fh.write("foo\nbar") self.useFixture( fixtures.EnvironmentVariable('PBR_REQUIREMENTS_FILES', self.tmp_file)) self.assertEqual(['foo', 'bar'], packaging.parse_requirements())
Example #11
Source File: test_shell.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_defaults_to_process_environment(self): name = factory.make_name("name") value = factory.make_name("value") with EnvironmentVariable(name, value): self.assertThat( get_env_with_bytes_locale(), ContainsDict( {name.encode("ascii"): Equals(value.encode("ascii"))} ), )
Example #12
Source File: testing.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def patch_dns_config_path(testcase, config_dir=None): """Set the DNS config dir to a temporary directory, and return its path.""" if config_dir is None: config_dir = testcase.make_dir() testcase.useFixture(EnvironmentVariable("MAAS_DNS_CONFIG_DIR", config_dir)) testcase.useFixture( EnvironmentVariable("MAAS_BIND_CONFIG_DIR", config_dir) ) return config_dir
Example #13
Source File: testing.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def patch_dns_default_controls(testcase, enable): testcase.useFixture( EnvironmentVariable( "MAAS_DNS_DEFAULT_CONTROLS", "1" if enable else "0" ) )
Example #14
Source File: test_integration.py From keras-lambda with MIT License | 5 votes |
def setUp(self): # Integration tests need a higher default - big repos can be slow to # clone, particularly under guest load. env = fixtures.EnvironmentVariable( 'OS_TEST_TIMEOUT', os.environ.get('OS_TEST_TIMEOUT', '600')) with env: super(TestIntegration, self).setUp() base._config_git()
Example #15
Source File: test_shell.py From python-tackerclient with Apache License 2.0 | 5 votes |
def test_endpoint_environment_variable(self): fixture = fixtures.EnvironmentVariable("OS_ENDPOINT_TYPE", "public") self.useFixture(fixture) shell = openstack_shell.TackerShell(DEFAULT_API_VERSION) parser = shell.build_option_parser('descr', DEFAULT_API_VERSION) # $OS_ENDPOINT_TYPE but not --endpoint-type namespace = parser.parse_args([]) self.assertEqual("public", namespace.endpoint_type) # --endpoint-type and $OS_ENDPOINT_TYPE namespace = parser.parse_args(['--endpoint-type=admin']) self.assertEqual('admin', namespace.endpoint_type)
Example #16
Source File: test_ssl.py From python-tackerclient with Apache License 2.0 | 5 votes |
def setUp(self): super(TestSSL, self).setUp() self.useFixture(fixtures.EnvironmentVariable('OS_TOKEN', AUTH_TOKEN)) self.useFixture(fixtures.EnvironmentVariable('OS_URL', END_URL)) self.addCleanup(mock.patch.stopall)
Example #17
Source File: test_ssl.py From python-tackerclient with Apache License 2.0 | 5 votes |
def test_ca_cert_passed_as_env_var(self): self.useFixture(fixtures.EnvironmentVariable('OS_CACERT', CA_CERT)) self._test_verify_client_manager([])
Example #18
Source File: test_setup.py From keras-lambda with MIT License | 5 votes |
def setUp(self): super(GitLogsTest, self).setUp() self.temp_path = self.useFixture(fixtures.TempDir()).path self.root_dir = os.path.abspath(os.path.curdir) self.git_dir = os.path.join(self.root_dir, ".git") self.useFixture( fixtures.EnvironmentVariable('SKIP_GENERATE_AUTHORS')) self.useFixture( fixtures.EnvironmentVariable('SKIP_WRITE_GIT_CHANGELOG'))
Example #19
Source File: test_core.py From keras-lambda with MIT License | 5 votes |
def test_console_script_install(self): """Test that we install a non-pkg-resources console script.""" if os.name == 'nt': self.skipTest('Windows support is passthrough') stdout, _, return_code = self.run_setup( 'install_scripts', '--install-dir=%s' % self.temp_dir) self.useFixture( fixtures.EnvironmentVariable('PYTHONPATH', '.')) self.check_script_install(stdout)
Example #20
Source File: test_config.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_get_bind_config_dir_checks_environ_first(self): directory = self.make_dir() self.useFixture(EnvironmentVariable("MAAS_BIND_CONFIG_DIR", directory)) self.assertThat( config.get_bind_config_dir(), MatchesAll(SamePath(directory), IsInstance(str)), )
Example #21
Source File: test_shell.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_defaults_to_process_environment(self): name = factory.make_name("name") value = factory.make_name("value") with EnvironmentVariable(name, value): self.assertThat( get_env_with_locale(), ContainsDict({name: Equals(value)}) )
Example #22
Source File: test_snappy.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def _write_snap_mode(self, mode): snap_common_path = Path(self.make_dir()) snap_mode_path = snap_common_path.joinpath("snap_mode") if mode is not None: snap_mode_path.write_text(mode, "utf-8") self.useFixture( EnvironmentVariable("SNAP_COMMON", str(snap_common_path)) )
Example #23
Source File: test_snappy.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def _get_snap_version(self, snap_yaml): """Arrange for `snap_yaml` to be loaded by `get_snap_version`. Puts `snap_yaml` at $tmpdir/meta/snap.yaml, sets SNAP=$tmpdir in the environment, then calls `get_snap_version`. """ snap_path = Path(self.make_dir()) snap_yaml_path = snap_path.joinpath("meta", "snap.yaml") snap_yaml_path.parent.mkdir() snap_yaml_path.write_text(snap_yaml, "utf-8") with EnvironmentVariable("SNAP", str(snap_path)): return snappy.get_snap_version()
Example #24
Source File: test_fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_removes_https_proxy_from_environment(self): https_proxy = factory.make_name("https-proxy") initial = EnvironmentVariable("https_proxy", https_proxy) self.useFixture(initial) # On entry, https_proxy is removed from the environment. with ProxiesDisabledFixture(): self.assertNotIn("https_proxy", os.environ) # On exit, http_proxy is restored. self.assertEqual(https_proxy, os.environ.get("https_proxy"))
Example #25
Source File: test_fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_removes_http_proxy_from_environment(self): http_proxy = factory.make_name("http-proxy") initial = EnvironmentVariable("http_proxy", http_proxy) self.useFixture(initial) # On entry, http_proxy is removed from the environment. with ProxiesDisabledFixture(): self.assertNotIn("http_proxy", os.environ) # On exit, http_proxy is restored. self.assertEqual(http_proxy, os.environ.get("http_proxy"))
Example #26
Source File: fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def _setUp(self): self.path = self.useFixture(TempDirectory()).join("maas-data") os.mkdir(self.path) self.useFixture(EnvironmentVariable("MAAS_DATA", self.path))
Example #27
Source File: fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def _setUp(self): skel = Path(root).joinpath("run-skel") if skel.is_dir(): self.path = self.useFixture(TempDirectory()).join("run") # Work only in `run`; reference the old $MAAS_ROOT. etc = Path(self.path).joinpath("etc") # Create and populate $MAAS_ROOT/run/etc/{chrony,c/chrony.conf}. # The `.keep` file is not strictly necessary, but it's created for # consistency with the source tree's `run` directory. ntp = etc.joinpath("chrony") ntp.mkdir(parents=True) ntp.joinpath(".keep").touch() ntp_conf = ntp.joinpath("chrony.conf") ntp_conf.write_bytes( skel.joinpath("etc", "chrony", "chrony.conf").read_bytes() ) # Create and populate $MAAS_ROOT/run/etc/maas. maas = etc.joinpath("maas") maas.mkdir(parents=True) maas.joinpath("drivers.yaml").symlink_to( skel.joinpath("etc", "maas", "drivers.yaml").resolve() ) maas.joinpath("templates").mkdir() # Update the environment. self.useFixture(EnvironmentVariable("MAAS_ROOT", self.path)) else: raise NotADirectoryError( "Skeleton MAAS_ROOT (%s) is not a directory." % skel )
Example #28
Source File: fixtures.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): super().setUp() self.useFixture(EnvironmentVariable("http_proxy")) self.useFixture(EnvironmentVariable("https_proxy"))
Example #29
Source File: test_create.py From reno with Apache License 2.0 | 5 votes |
def test_edit_without_editor_env_var(self): self.useFixture(fixtures.EnvironmentVariable('EDITOR')) with mock.patch('subprocess.call') as call_mock: self.assertFalse(create._edit_file('somepath')) call_mock.assert_not_called()
Example #30
Source File: test_create.py From reno with Apache License 2.0 | 5 votes |
def test_edit(self): self.useFixture(fixtures.EnvironmentVariable('EDITOR', 'myeditor')) with mock.patch('subprocess.call') as call_mock: self.assertTrue(create._edit_file('somepath')) call_mock.assert_called_once_with(['myeditor', 'somepath'])