Best Python code snippet using behave
json.format.py
Source: json.format.py
...60 outfile.write(contents2)61 outfile.close()62 console.warn("%s OK", message)63 return 1 #< OK64def json_formatall(filenames, indent=DEFAULT_INDENT_SIZE, dry_run=False):65 """66 Format/Beautify a JSON file.67 :param filenames: Format one or more JSON files.68 :param indent: Number of chars to indent per level (default: 4).69 :returns: 0, if successful. Otherwise, number of errors.70 """71 errors = 072 console = logging.getLogger("console")73 for filename in filenames:74 try:75 result = json_format(filename, indent=indent, console=console,76 dry_run=dry_run)77 if not result:78 errors += 179# except json.decoder.JSONDecodeError, e:80# console.error("ERROR: %s (filename: %s)", e, filename)81# errors += 182 except Exception as e:83 console.error("ERROR %s: %s (filename: %s)",84 e.__class__.__name__, e, filename)85 errors += 186 return errors87# ----------------------------------------------------------------------------88# MAIN FUNCTION:89# ----------------------------------------------------------------------------90def main(args=None):91 """Boilerplate for this script."""92 if args is None:93 args = sys.argv[1:]94 usage_ = """%prog [OPTIONS] JsonFile [MoreJsonFiles...]95Format/Beautify one or more JSON file(s)."""96 parser = OptionParser(usage=usage_, version=VERSION)97 parser.add_option("-i", "--indent", dest="indent_size",98 default=DEFAULT_INDENT_SIZE, type="int",99 help="Indent size to use (default: %default).")100 parser.add_option("-c", "--compact", dest="compact",101 action="store_true", default=False,102 help="Use compact format (default: %default).")103 parser.add_option("-n", "--dry-run", dest="dry_run",104 action="store_true", default=False,105 help="Check only if JSON is well-formed (default: %default).")106 options, filenames = parser.parse_args(args) #< pylint: disable=W0612107 if not filenames:108 parser.error("OOPS, no filenames provided.")109 if options.compact:110 options.indent_size = None111 # -- STEP: Init logging subsystem.112 format_ = "json.format: %(message)s"113 logging.basicConfig(level=logging.WARN, format=format_)114 console = logging.getLogger("console")115 # -- DOS-SHELL SUPPORT: Perform filename globbing w/ wildcards.116 skipped = 0117 filenames2 = []118 for filename in filenames:119 if "*" in filenames:120 files = glob.glob(filename)121 filenames2.extend(files)122 elif os.path.isdir(filename):123 # -- CONVENIENCE-SHORTCUT: Use DIR as shortcut for JSON files.124 files = glob.glob(os.path.join(filename, "*.json"))125 filenames2.extend(files)126 if not files:127 console.info("SKIP %s, no JSON files found in dir.", filename)128 skipped += 1129 elif not os.path.exists(filename):130 console.warn("SKIP %s, file not found.", filename)131 skipped += 1132 continue133 else:134 assert os.path.exists(filename)135 filenames2.append(filename)136 filenames = filenames2137 # -- NORMAL PROCESSING:138 errors = json_formatall(filenames, options.indent_size,139 dry_run=options.dry_run)140 console.error("Processed %d files (%d with errors, skipped=%d).",141 len(filenames), errors, skipped)142 if not filenames:143 errors += 1144 return errors145# ----------------------------------------------------------------------------146# AUTO-MAIN:147# ----------------------------------------------------------------------------148if __name__ == "__main__":...
Check out the latest blogs from LambdaTest on this topic:
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium Cucumber Tutorial.
This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Selenium JavaScript Tutorial.
Headless browsers are gaining popularity as a viable option for testing web applications. As we all know, web browsers are an integral part of automation testing using Selenium Webdriver. While performing Selenium automation testing, Selenium launches the corresponding browser defined in the script during the test run and then executes test steps. However, issues like the slow rendering of web pages can be a potential issue that can delay the test execution speed. As a solution, headless browser testing was introduced to speed up test execution time.
Selenium is one of the most prominent automation frameworks for functional testing and web app testing. Automation testers who use Selenium can run tests across different browser and platform combinations by leveraging an online Selenium Grid, you can learn more about what Is Selenium? Though Selenium is the go-to framework for test automation, Cypress – a relatively late entrant in the test automation game has been catching up at a breakneck pace.
WordPress is like a lighthouse, that lightens up 30% of the internet. Pivotal reason behind it’s huge success is the level of customization that it offers along with huge amount of community support in the form of plugins, themes, extensions, etc. .
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!