def setup_ctx(test, error): sch = 'v5_errors/error_'+test test = 'test_sch_errors_'+test ctx = context.TestContextSCH(test, sch, 'int_bom_simple_csv', None) ctx.run(CORRUPTED_SCH) ctx.search_err(error) ctx.clean_up()
def test_sch_not_found(): """ When the provided .sch isn't there """ prj = 'good-project' ctx = context.TestContextSCH('Schematic_not_found', prj) cmd = [PROG, 'run_erc'] ctx.run(cmd, NO_SCHEMATIC, filename='dummy') m = ctx.search_err(r'ERROR:.* does not exist') assert m is not None ctx.clean_up()
def test_erc_filter_bad_name(): """ Wrong filter name. """ prj = 'fail-project' ctx = context.TestContextSCH('ERC_Filter_Bad_Name', prj) cmd = [PROG, '-v', 'run_erc', '-f', ctx.get_prodir_filename('bogus')] ctx.run(cmd, WRONG_ARGUMENTS) m = ctx.search_err(r"Filter file (.*) doesn't exist") assert m is not None ctx.clean_up()
def test_export_all_pdf(test_dir): prj = 'good-project' pdf = prj + '.pdf' ctx = context.TestContextSCH(test_dir, 'Export_All_PDF', prj) cmd = [PROG, '-vv', '-r', 'export', '--file_format', 'pdf', '--all_pages'] ctx.run(cmd) ctx.expect_out_file(pdf) ctx.compare_pdf(pdf, 'good_sch_all.pdf') ctx.clean_up()
def test_bom_cfg_1(test_dir): prj = 'bom' ctx = context.TestContextSCH(test_dir, 'test_bom_cfg_1', prj, 'bom_cfg', BOM_DIR) ctx.run() name = os.path.join(BOM_DIR, prj) csv = name+'-bom.csv' ctx.expect_out_file(csv) ctx.search_in_file(csv, ['R,R1,100 R_0805_2012Metric ~', 'R,R2,200 R_0805_2012Metric ~', 'C,C1,1uF C_0805_2012Metric ~']) ctx.clean_up()
def test_sch_no_extension(): """ KiCad can't load a schematic file without extension """ prj = 'good-project' ctx = context.TestContextSCH('SCH_no_extension', prj) cmd = [PROG, 'run_erc'] ctx.run(cmd, WRONG_SCH_NAME, filename='Makefile') m = ctx.search_err(r'Schematic files must use sch extension') assert m is not None ctx.clean_up()
def test_erc_warning_fail(): prj = 'warning-project' ctx = context.TestContextSCH('ERC_Warning_as_Error', prj) cmd = [PROG, 'run_erc', '--warnings_as_errors'] ctx.run(cmd, 255) ctx.expect_out_file(prj + '.erc') m = ctx.search_err(OUT_ERR_REX) assert m is not None assert m.group(1) == '1' ctx.clean_up()
def test_erc_warning(): prj = 'warning-project' ctx = context.TestContextSCH('ERC_Warning', prj) cmd = [PROG, 'run_erc'] ctx.run(cmd, 0) ctx.expect_out_file(prj + '.erc') m = ctx.search_err(OUT_WAR_REX) assert m is not None assert m.group(1) == '1' ctx.clean_up()
def test_erc_error(): """ Here we have a missing library """ prj = 'missing-lib' rep = prj + '.erc' ctx = context.TestContextSCH('ERC_Error', prj) cmd = [PROG, 'run_erc'] ctx.run(cmd) ctx.expect_out_file(rep) assert ctx.search_err(r"Missing library") is not None ctx.clean_up()
def test_erc_remap(): """ Here we use a KiCad 4 .sch that needs symbol remapping """ prj = 'kicad4-project' rep = prj + '.erc' ctx = context.TestContextSCH('ERC_Remap', prj) cmd = [PROG, 'run_erc'] ctx.run(cmd) ctx.expect_out_file(rep) assert ctx.search_err(r"Schematic needs update") is not None ctx.clean_up()
def test_export_dxf(): prj = 'good-project' dxf = prj + '.dxf' ctx = context.TestContextSCH('Export_DXF', prj) cmd = [PROG, 'export', '--file_format', 'dxf'] ctx.run(cmd) ctx.expect_out_file(dxf) ctx.dont_expect_out_file('logic-logic.dxf') ctx.dont_expect_out_file('power-Power.dxf') ctx.clean_up()
def test_kicad_conf_bad_sym_lib_table(): """ Check various problems in the sym-lib-table file """ sch = 'sym-lib-table_errors/kibom-test' test = 'test_kicad_conf_bad_sym_lib_table' ctx = context.TestContextSCH(test, sch, 'int_bom_simple_csv', None) ctx.run(EXIT_BAD_CONFIG, extra_debug=True) ctx.search_err('Malformed lib entry') ctx.search_err(r'Unable to expand .?BOGUS.? in') ctx.search_err(r'unnamed LibAlias') ctx.clean_up()
def test_bom_cfg_3(): """ Without any column """ prj = 'bom' ctx = context.TestContextSCH('test_bom_cfg_3', prj, 'bom_cfg3', BOM_DIR) ctx.run() name = os.path.join(BOM_DIR, prj) csv = name + '-bom.csv' ctx.expect_out_file(csv) ctx.search_in_file(csv, ['R,R1,100', 'R,R2,200', 'C,C1,1uF']) ctx.clean_up()
def test_erc_warning_1(test_dir): """ Using an SCH with ERC warnings """ prj = 'warning-project' ctx = context.TestContextSCH(test_dir, 'test_erc_warning_1', 'erc_warning/' + prj, 'erc', '') ctx.run() # Check all outputs are there ctx.expect_out_file(prj + '-erc.txt') ctx.search_err(r"WARNING:\(W058\) 1 ERC warnings detected") ctx.clean_up()
def test_erc_warning_2(test_dir): """ Using an SCH with ERC warnings as errors """ prj = 'warning-project' ctx = context.TestContextSCH(test_dir, 'test_erc_warning_1', 'erc_warning/' + prj, 'erc_no_w', '') ctx.run(ERC_ERROR) # Check all outputs are there ctx.expect_out_file(prj + '-erc.txt') ctx.search_err(r"ERROR:1 ERC errors detected") ctx.clean_up()
def test_export_ps(): prj = 'good-project' ps = prj + '.ps' ctx = context.TestContextSCH('Export_PS', prj) cmd = [PROG, '-vv', '-r', 'export', '--file_format', 'ps'] ctx.run(cmd) ctx.compare_ps(ps) ctx.dont_expect_out_file(ctx.get_sub_sheet_name('logic', 'ps')) ctx.dont_expect_out_file(ctx.get_sub_sheet_name('Power', 'ps')) ctx.clean_up()
def test_export_hpgl(): prj = 'good-project' hpgl = prj + '.plt' ctx = context.TestContextSCH('Export_HPGL', prj) cmd = [PROG, '-vv', '-r', 'export', '--file_format', 'hpgl'] ctx.run(cmd) ctx.expect_out_file(hpgl) ctx.dont_expect_out_file(ctx.get_sub_sheet_name('logic', 'dxf')) ctx.dont_expect_out_file(ctx.get_sub_sheet_name('Power', 'plt')) ctx.clean_up()
def test_export_all_ps(): prj = 'good-project' ps = prj + '.ps' ctx = context.TestContextSCH('Export_All_PS', prj) cmd = [PROG, 'export', '--file_format', 'ps', '--all_pages'] ctx.run(cmd) ctx.compare_ps(ps) ctx.compare_ps('logic-logic.ps') ctx.compare_ps('power-Power.ps') ctx.clean_up()
def test_export_all_dxf(test_dir): prj = 'good-project' dxf = prj + '.dxf' ctx = context.TestContextSCH(test_dir, 'Export_All_DXF', prj) cmd = [PROG, '-vv', '-r', 'export', '--file_format', 'dxf', '--all_pages'] ctx.run(cmd) ctx.expect_out_file(dxf) ctx.expect_out_file(ctx.get_sub_sheet_name('logic', 'dxf')) ctx.expect_out_file(ctx.get_sub_sheet_name('Power', 'dxf')) ctx.clean_up()
def test_export_all_hpgl(test_dir): prj = 'good-project' hpgl = prj + '.plt' ctx = context.TestContextSCH(test_dir, 'Export_All_HPGL', prj) cmd = [PROG, 'export', '--file_format', 'hpgl', '--all_pages'] ctx.run(cmd) ctx.expect_out_file(hpgl) ctx.expect_out_file(ctx.get_sub_sheet_name('logic', 'plt')) ctx.expect_out_file(ctx.get_sub_sheet_name('Power', 'plt')) ctx.clean_up()
def test_export_all_hpgl(): prj = 'good-project' hpgl = prj + '.plt' ctx = context.TestContextSCH('Export_All_HPGL', prj) cmd = [PROG, 'export', '--file_format', 'hpgl', '--all_pages'] ctx.run(cmd) ctx.expect_out_file(hpgl) ctx.expect_out_file('logic-logic.plt') ctx.expect_out_file('power-Power.plt') ctx.clean_up()
def test_print_sch_variant_ni_1(): """ Using a variant """ prj = 'test_v5' # Is the most complete, contains every KiCad object I know ctx = context.TestContextSCH('test_print_sch_variant_ni_1', prj, 'print_pdf_no_inductors_1', PDF_DIR) ctx.run() r_name = 'test_v5-schematic_(no_L).pdf' o_name = os.path.join(NI_DIR, r_name) ctx.expect_out_file(o_name) ctx.compare_pdf(o_name, r_name) ctx.clean_up()
def test_export_all_ps(test_dir): prj = 'good-project' ps = prj + '.ps' ctx = context.TestContextSCH(test_dir, 'Export_All_PS', prj) cmd = [PROG, '-vv', '-r', 'export', '--file_format', 'ps', '--all_pages'] ctx.run(cmd) ctx.compare_ps(ps) ctx.compare_ps(ctx.get_sub_sheet_name('logic', 'ps')) ctx.compare_ps(ctx.get_sub_sheet_name('Power', 'ps')) ctx.clean_up()
def test_bogus_sch(): """ A broken SCH file """ ctx = context.TestContextSCH('Bogus_SCH', 'good-project') sch = ctx.get_out_path(BOGUS_SCH) # Create an invalid SCH with open(sch, 'w') as f: f.write('dummy') cmd = [PROG, 'run_erc'] ctx.run(cmd, EESCHEMA_ERROR, filename=sch) assert ctx.search_err(r"eeschema reported an error") is not None ctx.clean_up()
def test_bom_cfg_2(): prj = 'bom' ctx = context.TestContextSCH('test_bom_cfg_2', prj, 'bom_cfg2', BOM_DIR) ctx.run() name = os.path.join(BOM_DIR, prj) csv = name + '-bom.csv' ctx.expect_out_file(csv) ctx.search_in_file( csv, ['R,100 R_0805_2012Metric,R1', 'R,200 R_0805_2012Metric,R2']) ctx.search_not_in_file(csv, ['C,1uF C_0805_2012Metric,C1']) ctx.clean_up()
def test_kicost_simple(test_dir): ''' External KiCost using variants, very simple case ''' prj = 'kibom-variant_kicost' ctx = context.TestContextSCH(test_dir, 'test_kicost_simple', prj, 'kicost_simple', OUT_DIR) ctx.run() check_simple(ctx, '') check_simple(ctx, 'default') check_simple(ctx, 'production') check_simple(ctx, 'test') ctx.clean_up()
def test_kicost_bom_merge_1(test_dir): ''' Internal BoM + KiCost, merging 3 projects. ''' prj = 'merge_1' ctx = context.TestContextSCH(test_dir, 'test_kicost_bom_merge_1', prj, 'int_bom_kicost_merge_xlsx', OUT_DIR) ctx.run(kicost=True) # , extra_debug=True output = op.join(OUT_DIR, prj + '-bom.xlsx') ctx.expect_out_file(output) convert2csv(ctx.get_out_path(output), sheet='Costs') csv = output[:-4] + 'csv' ctx.compare_txt(csv)
def test_sch_missing(): """ R1 exists in l1.lib, but the lib isn't specified. R2 is bogus, completely missing """ prj = 'missing' ctx = context.TestContextSCH('test_sch_missing', prj, 'sch_no_inductors_1', PDF_DIR) ctx.run() o_name = os.path.join(NI_DIR, prj+'.sch') ctx.expect_out_file(o_name) ctx.search_err("Component .?Resistor.? doesn't specify its library") ctx.search_err("Missing component .?l1:FooBar.?") ctx.search_err("Missing component(.*)Resistor", invert=True) ctx.clean_up()
def test_erc_error(test_dir): """ Here we have a missing library. On KiCad 6 there is no need for the libs. """ prj = 'missing-lib' rep = prj + '.erc' ctx = context.TestContextSCH(test_dir, 'ERC_Error', prj) if ctx.kicad_version < context.KICAD_VERSION_5_99: cmd = [PROG, 'run_erc'] ctx.run(cmd) ctx.expect_out_file(rep) assert ctx.search_err(r"Missing library") is not None ctx.clean_up()
def test_erc_filter_bad_syntax(): """ Wrong filter name. """ prj = 'fail-project' ctx = context.TestContextSCH('ERC_Filter_Bad_Syntax', prj) cmd = [ PROG, '-v', 'run_erc', '-f', ctx.get_prodir_filename('fail-project.sch') ] ctx.run(cmd, WRONG_ARGUMENTS) m = ctx.search_err(r"Syntax error at line \d+ in filter file") assert m is not None ctx.clean_up()