Esempio n. 1
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
Esempio n. 2
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'
Esempio n. 3
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()
Esempio n. 4
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 = ''
Esempio n. 5
0
#!/usr/bin/python3
import os
import sys
# Setup the path to load local kibot module
cur_dir = os.path.dirname(os.path.abspath(__file__))
prev_dir = os.path.dirname(os.path.dirname(cur_dir))
if prev_dir not in sys.path:
    sys.path.insert(0, prev_dir)
if len(sys.argv) > 1 and sys.argv[1] == 'fake':
    fake_dir = os.path.join(cur_dir, 'fake_pcbnew')
    if fake_dir not in sys.path:
        sys.path.insert(0, fake_dir)
else:
    # Force the pcbnew module load to fail
    sys.modules['pcbnew'] = None
# Import the module to test
from kibot.__main__ import detect_kicad
detect_kicad()