How to use config_get method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...23 def test_configure_get_command(self):24 session = FakeSession({})25 session.config['region'] = 'us-west-2'26 stream, error_stream, config_get = self.create_command(session)27 config_get(args=['region'], parsed_globals=None)28 rendered = stream.getvalue()29 self.assertEqual(rendered.strip(), 'us-west-2')30 def test_configure_get_command_no_exist(self):31 no_vars_defined = {}32 session = FakeSession(no_vars_defined)33 stream, error_stream, config_get = self.create_command(session)34 rc = config_get(args=['region'], parsed_globals=None)35 rendered = stream.getvalue()36 # If a config value does not exist, we don't print any output.37 self.assertEqual(rendered, '')38 # And we exit with an rc of 1.39 self.assertEqual(rc, 1)40 def test_dotted_get(self):41 session = FakeSession({})42 session.full_config = {'preview': {'emr': 'true'}}43 stream, error_stream, config_get = self.create_command(session)44 config_get(args=['preview.emr'], parsed_globals=None)45 rendered = stream.getvalue()46 self.assertEqual(rendered.strip(), 'true')47 def test_dotted_get_with_profile(self):48 session = FakeSession({})49 session.full_config = {'profiles': {'emr-dev': {50 'emr': {'instance_profile': 'my_ip'}}}}51 session.config = {'emr': {'instance_profile': 'my_ip'}}52 stream, error_stream, config_get = self.create_command(session)53 config_get(args=['emr-dev.emr.instance_profile'], parsed_globals=None)54 rendered = stream.getvalue()55 self.assertEqual(rendered.strip(), 'my_ip')56 def test_get_from_profile(self):57 session = FakeSession({})58 session.full_config = {59 'profiles': {'testing': {'aws_access_key_id': 'access_key'}}}60 stream, error_stream, config_get = self.create_command(session)61 config_get = ConfigureGetCommand(session, stream)62 config_get(args=['profile.testing.aws_access_key_id'],63 parsed_globals=None)64 rendered = stream.getvalue()65 self.assertEqual(rendered.strip(), 'access_key')66 def test_get_nested_attribute(self):67 session = FakeSession({})68 session.full_config = {69 'profiles': {'testing': {'s3': {'signature_version': 's3v4'}}}}70 stream, error_stream, config_get = self.create_command(session)71 config_get(args=['profile.testing.s3.signature_version'],72 parsed_globals=None)73 rendered = stream.getvalue()74 self.assertEqual(rendered.strip(), 's3v4')75 def test_get_nested_attribute_from_default(self):76 session = FakeSession({})77 session.full_config = {78 'profiles': {'default': {'s3': {'signature_version': 's3v4'}}}}79 stream, error_stream, config_get = self.create_command(session)80 config_get(args=['default.s3.signature_version'],81 parsed_globals=None)82 rendered = stream.getvalue()83 self.assertEqual(rendered.strip(), 's3v4')84 def test_get_nested_attribute_from_default_does_not_exist(self):85 session = FakeSession({})86 session.full_config = {'profiles': {}}87 stream, error_stream, config_get = self.create_command(session)88 config_get(args=['default.s3.signature_version'],89 parsed_globals=None)90 rendered = stream.getvalue()91 self.assertEqual(rendered.strip(), '')92 def test_get_nested_attribute_from_implicit_default(self):93 session = FakeSession({})94 session.full_config = {95 'profiles': {'default': {'s3': {'signature_version': 's3v4'}}}}96 stream, error_stream, config_get = self.create_command(session)97 config_get(args=['s3.signature_version'],98 parsed_globals=None)99 rendered = stream.getvalue()100 self.assertEqual(rendered.strip(), 's3v4')101 def test_get_section_returns_error(self):102 session = FakeSession({})103 session.full_config = {104 'profiles': {'default': {'s3': {'signature_version': 's3v4'}}}}105 session.config = {'s3': {'signature_version': 's3v4'}}106 stream, error_stream, config_get = self.create_command(session)107 rc = config_get(args=['s3'], parsed_globals=None)108 self.assertEqual(rc, 1)109 error_message = error_stream.getvalue()110 expected_message = (111 'varname (s3) must reference a value, not a section or '112 'sub-section.')113 self.assertEqual(error_message, expected_message)114 self.assertEqual(stream.getvalue(), '')115 def test_get_non_string_returns_error(self):116 # This should never happen, but we handle this case so we should117 # test it.118 session = FakeSession({})119 session.full_config = {120 'profiles': {'default': {'foo': object()}}}121 stream, error_stream, config_get = self.create_command(session)122 rc = config_get(args=['foo'], parsed_globals=None)123 self.assertEqual(rc, 1)124 self.assertEqual(stream.getvalue(), '')...

Full Screen

Full Screen Github


Full Screen

...26LOG_LEVEL = "WARNING"27FEED_TIMEOUT = 20 # seconds28# Default template file list29TEMPLATE_FILES = "examples/basic/planet.html.tmpl"30def config_get(config, section, option, default=None, raw=0, vars=None):31 """Get a value from the configuration, with a default."""32 if config.has_option(section, option):33 return config.get(section, option, raw=raw, vars=None)34 else:35 return default36def main():37 config_file = CONFIG_FILE38 offline = 039 verbose = 040 for arg in sys.argv[1:]:41 if arg == "-h" or arg == "--help":42 print "Usage: planet [options] [CONFIGFILE]"43 print44 print "Options:"45 print " -v, --verbose DEBUG level logging during update"46 print " -o, --offline Update the Planet from the cache only"47 print " -h, --help Display this help message and exit"48 print49 sys.exit(0)50 elif arg == "-v" or arg == "--verbose":51 verbose = 152 elif arg == "-o" or arg == "--offline":53 offline = 154 elif arg.startswith("-"):55 print >>sys.stderr, "Unknown option:", arg56 sys.exit(1)57 else:58 config_file = arg59 # Read the configuration file60 config = ConfigParser()61 if not config.has_section("Planet"):63 print >>sys.stderr, "Configuration missing [Planet] section."64 sys.exit(1)65 # Read the [Planet] config section66 planet_name = config_get(config, "Planet", "name", PLANET_NAME)67 planet_link = config_get(config, "Planet", "link", PLANET_LINK)68 planet_feed = config_get(config, "Planet", "feed", PLANET_FEED)69 owner_name = config_get(config, "Planet", "owner_name", OWNER_NAME)70 owner_email = config_get(config, "Planet", "owner_email", OWNER_EMAIL)71 if verbose:72 log_level = "DEBUG"73 else:74 log_level = config_get(config, "Planet", "log_level", LOG_LEVEL)75 feed_timeout = config_get(config, "Planet", "feed_timeout", FEED_TIMEOUT)76 template_files = config_get(config, "Planet", "template_files",77 TEMPLATE_FILES).split(" ")78 # Default feed to the first feed for which there is a template79 if not planet_feed:80 for template_file in template_files:81 name = os.path.splitext(os.path.basename(template_file))[0]82 if name.find('atom')>=0 or name.find('rss')>=0:83 planet_feed = urlparse.urljoin(planet_link, name)84 break85 # Define locale86 if config.has_option("Planet", "locale"):87 # The user can specify more than one locale (separated by ":") as88 # fallbacks.89 locale_ok = False90 for user_locale in config.get("Planet", "locale").split(':'):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?