示例#1
0
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
示例#2
0
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
示例#3
0
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
示例#4
0
def check_load_conf(caplog,
                    dir='kicad',
                    fail=False,
                    catch_conf_error=False,
                    no_conf_path=False):
    caplog.set_level(logging.DEBUG)
    kiconf_de_init()
    import pcbnew
    GS.kicad_conf_path = None if no_conf_path else pcbnew.GetKicadConfigPath()
    with context.cover_it(cov):
        if catch_conf_error:
            with pytest.raises(KiConfError) as err:
                KiConf.init(
                    os.path.join(context.BOARDS_DIR,
                                 'v5_errors/kibom-test.sch'))
        else:
            KiConf.init(
                os.path.join(context.BOARDS_DIR, 'v5_errors/kibom-test.sch'))
            # Check we can call it again and nothing is done
            KiConf.init('bogus')
            err = None
    ref = 'Reading KiCad config from `tests/data/' + dir + '/kicad_common`'
    if fail:
        ref = 'Unable to find KiCad configuration file'
    assert ref in caplog.text, caplog.text
    return err
示例#5
0
def test_layer_no_id():
    with context.cover_it(cov):
        la = Layer()
        la.layer = 'F.Cu'
        la.description = 'Top'
        la.suffix = 'F_Cu'
        assert str(la) == "F.Cu ('Top' F_Cu)"
示例#6
0
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'
示例#7
0
def test_kicad_conf_no_instance():
    """ Check we can't create a KiConf instance """
    with context.cover_it(cov):
        with pytest.raises(AssertionError) as pytest_wrapped_e:
            o = KiConf()  # noqa: F841
    assert pytest_wrapped_e.type == AssertionError
    assert str(pytest_wrapped_e.value
               ) == 'KiConf is fully static, no instances allowed'
示例#8
0
def test_kicad_conf_local_conf(caplog, monkeypatch):
    """ Test if we can use the 'posix_user' """
    global _real_posix_prefix
    _real_posix_prefix = sysconfig.get_path('data', 'posix_prefix')
    with monkeypatch.context() as m:
        m.setattr("sysconfig.get_path", mocked_get_path_1)
        with context.cover_it(cov):
            assert KiConf.guess_symbol_dir() == '/usr/share/kicad/library'
示例#9
0
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)
示例#10
0
def test_makefile_kibot_sys(test_dir):
    ctx = context.TestContext(test_dir, 'test_makefile_kibot_sys', 'test_v5', 'empty_zip', '')
    GS.sch_file = 'foo.sch'
    GS.pcb_file = 'bar.kicad_pcb'
    GS.out_dir = ctx.get_out_path('')
    with context.cover_it(cov):
        generate_makefile(ctx.get_out_path('Makefile'), 'pp', [], kibot_sys=True)
    ctx.search_in_file('Makefile', [r'KIBOT\?=kibot'])
    ctx.clean_up()
示例#11
0
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
示例#12
0
def test_no_get_targets(caplog):
    test = NoGetTargets()
    test_pre = DummyPre()
    # Also check the dependencies fallback
    GS.sch = None
    GS.sch_file = 'fake'
    with context.cover_it(cov):
        test.get_targets('')
        files = test.get_dependencies()
        files_pre = test_pre.get_dependencies()
    assert "Output 'Fake' (dummy) [none] doesn't implement get_targets(), plese report it" in caplog.text
    assert files == [GS.sch_file]
    assert files_pre == [GS.sch_file]
示例#13
0
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()
示例#14
0
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 = ''
示例#15
0
def test_unknown_prefix(caplog):
    with context.cover_it(cov):
        get_prefix('y')
    assert 'Unknown prefix, please report' in caplog.text
示例#16
0
def test_unimplemented_layer(caplog):
    with context.cover_it(cov):
        with pytest.raises(AssertionError) as e:
            Layer.solve(1)
    assert e.type == AssertionError
    assert e.value.args[0] == "Unimplemented layer type <class 'int'>"