def run_compress(ctx, test_import_fail=False): with context.cover_it(cov): # Load the plug-ins load_actions() # Create a compress object with the dummy file as source out = RegOutput.get_class_for('compress')() out.set_tree({ 'options': { 'format': 'RAR', 'files': [{ 'source': ctx.get_out_path('*') }] } }) out.config() # Setup the GS output dir, needed for the output path GS.out_dir = '.' # Run the compression and catch the error with pytest.raises(SystemExit) as pytest_wrapped_e: if test_import_fail: _import( 'out_bogus', os.path.abspath( os.path.join(os.path.dirname(__file__), 'fake_plugin/out_bogus.py'))) else: out.run('') return pytest_wrapped_e
def test_pre_xrc_fail(test_dir, caplog, monkeypatch): ctx = context.TestContext(test_dir, 'test_pre_xrc_fail', 'test_v5', 'empty_zip', '') global mocked_call_enabled mocked_call_enabled = True with monkeypatch.context() as m: patch_functions(m) with context.cover_it(cov): load_actions() GS.set_pcb(ctx.board_file) sch = ctx.board_file GS.set_sch(sch.replace('.kicad_pcb', '.sch')) GS.out_dir = test_dir pre_drc = BasePreFlight.get_class_for('run_drc')('run_drc', True) with pytest.raises(SystemExit) as e1: pre_drc.run() pre_erc = BasePreFlight.get_class_for('run_erc')('run_erc', True) with pytest.raises(SystemExit) as e2: pre_erc.run() out = RegOutput.get_class_for('pdf_pcb_print')() out.set_tree({'layers': 'all'}) out.config() with pytest.raises(SystemExit) as e3: out.run('') assert e1.type == SystemExit assert e1.value.code == DRC_ERROR assert e2.type == SystemExit assert e2.value.code == ERC_ERROR assert e3.type == SystemExit assert e3.value.code == PDF_PCB_PRINT assert CMD_PCBNEW_PRINT_LAYERS + ' returned 5' in caplog.text ctx.clean_up() mocked_call_enabled = False
def test_step_fail(test_dir, caplog, monkeypatch): global mocked_check_output_FNF mocked_check_output_FNF = False # Create a silly context to get the output path ctx = context.TestContext(test_dir, 'test_step_fail', 'test_v5', 'empty_zip', '') # We will patch subprocess.check_output to make rar fail with monkeypatch.context() as m: patch_functions(m) with context.cover_it(cov): detect_kicad() load_actions() GS.set_pcb(ctx.board_file) GS.board = None KiConf.loaded = False load_board() # Create a compress object with the dummy file as source out = RegOutput.get_class_for('step')() out.set_tree({}) out.config() with pytest.raises(SystemExit) as e: out.run('') # Check we exited because rar isn't installed assert e.type == SystemExit assert e.value.code == KICAD2STEP_ERR assert "Failed to create Step file, error 10" in caplog.text
def test_search_as_plugin_fail(test_dir, caplog): with context.cover_it(cov): detect_kicad() load_actions() dir_fake = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data') GS.kicad_plugins_dirs.append(dir_fake) fname = search_as_plugin('fake', ['']) assert fname == 'fake'
def test_var_rename_no_variant(): with context.cover_it(cov): # Load the plug-ins load_actions() # Create an ibom object filter = RegFilter.get_class_for('var_rename')() GS.variant = None # Should just return filter.filter(None)
def test_bom_no_sch(): with context.cover_it(cov): # Load the plug-ins load_actions() # Create an ibom object GS.sch = None out = RegOutput.get_class_for('bom')() columns = out.options._get_columns() assert columns == ColumnList.COLUMNS_DEFAULT out = RegOutput.get_class_for('kibom')() options = out.options() columns = options.conf._get_columns() assert columns == ColumnList.COLUMNS_DEFAULT
def test_search_as_plugin_ok(test_dir, caplog): ctx = context.TestContext(test_dir, 'test_search_as_plugin_ok', 'test_v5', 'empty_zip', '') with context.cover_it(cov): detect_kicad() load_actions() dir_fake = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data') GS.kicad_plugins_dirs.append(dir_fake) logging.debug('GS.kicad_plugins_dirs: '+str(GS.kicad_plugins_dirs)) fname = search_as_plugin('fake', ['fake_plugin']) logging.debug('fname: '+fname) with open(ctx.get_out_path('error.txt'), 'wt') as f: f.write(caplog.text) # Fails to collect caplog on docker image (TODO) # This is a bizarre case, the test alone works, all tests in test_misc* together work. # But when running all the tests this one fails to get caplog. # The test_rar_fail has a similar problem. # assert re.search(r"Using `(.*)data/fake_plugin/fake` for `fake` \(fake_plugin\)", caplog.text) is not None assert re.search(r"(.*)data/fake_plugin/fake", fname) is not None ctx.clean_up()
def test_ibom_parse_fail(test_dir, caplog, monkeypatch): global mocked_check_output_FNF mocked_check_output_FNF = False global mocked_check_output_retOK mocked_check_output_retOK = b'ERROR Parsing failed' # We will patch subprocess.check_output to make ibom fail with monkeypatch.context() as m: patch_functions(m) with context.cover_it(cov): detect_kicad() # Load the plug-ins load_actions() # Create an ibom object out = RegOutput.get_class_for('ibom')() out.set_tree({}) out.config() with pytest.raises(SystemExit) as pytest_wrapped_e: out.run('') assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == BOM_ERROR # logging.debug(caplog.text) assert "Failed to create BoM" in caplog.text mocked_check_output_retOK = ''