Best Python code snippet using hypothesis
__main__.py
Source:__main__.py  
1# -*- coding: utf-8 -*-2"""3    @package4    KiBOM - Bill of Materials generation for KiCad5    Generate BOM in xml, csv, txt, tsv, html or xlsx formats.6    - Components are automatically grouped into BoM rows (grouping is configurable)7    - Component groups count number of components and list component designators8    - Rows are automatically sorted by component reference(s)9    - Supports board variants10    Extended options are available in the "bom.ini" config file in the PCB directory (this file is auto-generated with default options the first time the script is executed).11    For usage help:12    python -m kibom -h13"""14from __future__ import print_function15import sys16import os17import argparse18import locale19from .columns import ColumnList20from .netlist_reader import netlist21from .bom_writer import WriteBoM22from .preferences import BomPref23from .version import KIBOM_VERSION24from . import debug25from .component import DNF26VARIANT_FIELD_SEPARATOR = ':'27def writeVariant(input_file, output_dir, output_file, variant, preferences):28    29    if variant is not None:30        preferences.pcbConfig = variant.strip().lower().split(',')31        32    debug.message("PCB variant:", ", ".join(preferences.pcbConfig))33    # Individual components34    components = []35    # Component groups36    groups = []37    # Read out the netlist38    net = netlist(input_file, prefs=preferences)39    # Extract the components40    components = net.getInterestingComponents()41    # Check if complex variant processing is enabled42    if preferences.complexVariant:43        # Process the variant fields44        do_not_populate = []45        for component in components:46            fields = component.getFieldNames()47            for field in fields:48                try:49                    # Find fields used for variant50                    [variant_name, field_name] = field.split(VARIANT_FIELD_SEPARATOR)51                except ValueError:52                    [variant_name, field_name] = [field, '']53                if variant_name.lower() in preferences.pcbConfig:54                    # Variant exist for component55                    variant_field_value = component.getField(field)56                    # Process no loaded option57                    if variant_field_value.lower() in DNF and not field_name:58                        do_not_populate.append(component)59                        break60                    # Write variant value to target field61                    component.setField(field_name, variant_field_value)62        # Process component dnp for specified variant63        if do_not_populate:64            updated_components = []65            for component in components:66                keep = True67                for dnp in do_not_populate:68                    # If component reference if found in dnp list: set for removal69                    if component.getRef() == dnp.getRef():70                        keep = False71                        break72                if keep:73                    # Component not in dnp list74                    updated_components.append(component)75                else:76                    # Component found in dnp list77                    do_not_populate.remove(component)78            # Finally update components list79            components = updated_components80    # Group the components81    groups = net.groupComponents(components)82    columns = ColumnList(preferences.corder)83    # Read out all available fields84    for g in groups:85        for f in g.fields:86            columns.AddColumn(f)87    # Don't add 'boards' column if only one board is specified88    if preferences.boards <= 1:89        columns.RemoveColumn(ColumnList.COL_GRP_BUILD_QUANTITY)90        debug.info("Removing:", ColumnList.COL_GRP_BUILD_QUANTITY)91    if output_file is None:92        output_file = input_file.replace(".xml", ".csv")93    output_name = os.path.basename(output_file)94    output_name, output_ext = os.path.splitext(output_name)95    # KiCad BOM dialog by default passes "%O" without an extension. Append our default96    if output_ext == "":97        output_ext = ".csv"98        debug.info("No extension supplied for output file - using .csv")99    elif output_ext not in [".xml", ".csv", ".txt", ".tsv", ".html", ".xlsx"]:100        output_ext = ".csv"101        debug.warning("Unknown extension '{e}' supplied - using .csv".format(e=output_ext))102    # Make replacements to custom file_name.103    file_name = preferences.outputFileName104    file_name = file_name.replace("%O", output_name)105    file_name = file_name.replace("%v", net.getVersion())106    if variant is not None:107        file_name = file_name.replace("%V", preferences.variantFileNameFormat)108        file_name = file_name.replace("%V", variant)109    else:110        file_name = file_name.replace("%V", "")111    output_file = os.path.join(output_dir, file_name + output_ext)112    output_file = os.path.abspath(output_file)113    debug.message("Saving BOM File:", output_file)114    return WriteBoM(output_file, groups, net, columns.columns, preferences)115def main():116    locale.setlocale(locale.LC_ALL, '')117    prog = 'KiBOM_CLI.py'118    if __name__ == '__main__':119        prog = "python -m kibom"120    parser = argparse.ArgumentParser(prog=prog, description="KiBOM Bill of Materials generator script")121    parser.add_argument("netlist", help='xml netlist file. Use "%%I" when running from within KiCad')122    parser.add_argument("output", default="", help='BoM output file name.\nUse "%%O" when running from within KiCad to use the default output name (csv file).\nFor e.g. HTML output, use "%%O.html"')123    parser.add_argument("-n", "--number", help="Number of boards to build (default = 1)", type=int, default=None)124    parser.add_argument("-v", "--verbose", help="Enable verbose output", action='count')125    parser.add_argument("-r", "--variant", help="Board variant(s), used to determine which components are output to the BoM. To specify multiple variants, with a BOM file exported for each variant, separate variants with the ';' (semicolon) character.", type=str, default=None)126    parser.add_argument("-d", "--subdirectory", help="Subdirectory within which to store the generated BoM files.", type=str, default=None)127    parser.add_argument("--cfg", help="BoM config file (script will try to use 'bom.ini' if not specified here)")128    parser.add_argument("-s", "--separator", help="CSV Separator (default ',')", type=str, default=None)129    parser.add_argument('--version', action='version', version="KiBOM Version: {v}".format(v=KIBOM_VERSION))130    args = parser.parse_args()131    # Set the global debugging level132    debug.setDebugLevel(int(args.verbose) if args.verbose is not None else debug.MSG_ERROR)133    debug.message("KiBOM version {v}".format(v=KIBOM_VERSION))134    135    input_file = os.path.abspath(args.netlist)136    input_dir = os.path.abspath(os.path.dirname(input_file))137    output_file = os.path.basename(args.output)138    if args.subdirectory is not None:139        output_dir = args.subdirectory140        if not os.path.isabs(output_dir):141            output_dir = os.path.join(input_dir, output_dir)142        # Make the directory if it does not exist143        if not os.path.exists(output_dir):144            os.makedirs(output_dir)145            debug.message("Creating subdirectory: '{d}'".format(d=output_dir))146    else:147        output_dir = os.path.abspath(os.path.dirname(input_file))148    debug.message("Output directory: '{d}'".format(d=output_dir))149    if not input_file.endswith(".xml"):150        debug.error("Input file '{f}' is not an xml file".format(f=input_file), fail=True)151    if not os.path.exists(input_file) or not os.path.isfile(input_file):152        debug.error("Input file '{f}' does not exist".format(f=input_file), fail=True)153    debug.message("Input:", input_file)154    # Look for a config file!155    # bom.ini by default156    ini = os.path.abspath(os.path.join(os.path.dirname(input_file), "bom.ini"))157    # Default value158    config_file = ini159    # User can overwrite with a specific config file160    if args.cfg:161        config_file = args.cfg162    # Read preferences from file. If file does not exists, default preferences will be used163    pref = BomPref()164    have_cfile = os.path.exists(config_file)165    if have_cfile:166        pref.Read(config_file)167        debug.message("Configuration file:", config_file)168    else:169        pref.Write(config_file)170        debug.info("Writing configuration file:", config_file)171    # Pass various command-line options through172    if args.number is not None:173        pref.boards = args.number174    pref.separatorCSV = args.separator175    if args.variant is not None:176        variants = args.variant.split(';')177    else:178        # Check if variants were defined in configuration179        if pref.pcbConfig != ['default']:180            variants = pref.pcbConfig181        else:182            variants = [None]183    # Generate BOMs for each specified variant184    for variant in variants:185        result = writeVariant(input_file, output_dir, output_file, variant, pref)186        if not result:187            debug.error("Error writing variant '{v}'".format(v=variant))188            sys.exit(-1)189    sys.exit(debug.getErrorCount())190if __name__ == '__main__':...0015_rawdata_do_not_populate.py
Source:0015_rawdata_do_not_populate.py  
1# Generated by Django 3.2.7 on 2022-04-09 16:302from django.db import migrations, models3class Migration(migrations.Migration):4    dependencies = [5        ('core', '0014_auto_20220406_0941'),6    ]7    operations = [8        migrations.AddField(9            model_name='rawdata',10            name='do_not_populate',11            field=models.BooleanField(default=False, help_text='Set this field if raw data should not propagate to CoPED catalogue (e.g. non-energy project).'),12        ),...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!!
