Пример #1
0
def test(c, setup=True):
    """
    Run Ki-nTree tests
    """

    try:
        c.run('pip show coverage', hide=True)
    except UnexpectedExit:
        c.run('pip install -U coverage', hide=True)

    cprint('[MAIN]\tRunning tests using coverage\n-----')
    if setup:
        c.run('cd InvenTree/ && inv server && cd ..', asynchronous=True)
        c.run('sleep 5')
        setup_inventree = c.run(
            'coverage run --parallel-mode -m kintree.setup_inventree')
        cprint('\n-----')
        c.run('cp -r tests/ kintree/')
        if setup_inventree.exited == 0:
            run_tests = c.run('coverage run --parallel-mode run_tests.py')
            if run_tests.exited == 0:
                c.run('coverage combine')
                coverage_report(c, open_browser=False)
    else:
        run_tests = c.run('coverage run run_tests.py')
        if run_tests.exited == 0:
            coverage_report(c, open_browser=False)
Пример #2
0
def coverage_report(c, open_browser=True):
    """
    Show coverage report
    """

    cprint('[MAIN]\tBuilding coverage report')
    c.run('coverage report')
    c.run('coverage html')
    if open_browser:
        webbrowser.open('htmlcov/index.html', new=2)
Пример #3
0
def build(c):
    """
    Build Ki-nTree into executable file
    """

    try:
        c.run('pip show pyinstaller', hide=True)
    except UnexpectedExit:
        c.run('pip install -U pyinstaller', hide=True)

    # Uninstall typing
    c.run('pip uninstall typing -y', hide=True)

    cprint('[MAIN]\tBuilding Ki-nTree GUI into "dist" directory')
    c.run('pyinstaller --clean --onefile -p kintree/kicad kintree_gui.py',
          hide=True)
Пример #4
0
def test(c):
    """
    Run Ki-nTree tests
    """

    try:
        c.run('pip show coverage', hide=True)
    except UnexpectedExit:
        c.run('pip install -U coverage', hide=True)

    cprint('[MAIN]\tRunning tests using coverage\n-----')
    # Start InvenTree server
    c.run('cd InvenTree/ && inv server && cd ..', asynchronous=True)
    c.run('sleep 5')
    # Copy test files
    c.run('cp -r tests/ kintree/')
    # Run Tests
    run_tests = c.run('coverage run run_tests.py')
    if run_tests.exited == 0:
        coverage_report(c, open_browser=False)
Пример #5
0
def clean(c):
    """
    Clean project folder
    """

    cprint('[MAIN]\tCleaning project directory')
    try:
        c.run('find . -name __pycache__ | xargs rm -r', hide='err')
    except UnexpectedExit:
        pass
    try:
        c.run('rm .coverage', hide='err')
    except UnexpectedExit:
        pass
    try:
        c.run('rm .coverage.*', hide='err')
    except UnexpectedExit:
        pass
    try:
        c.run('rm -r dist/ build/ htmlcov', hide='err')
    except UnexpectedExit:
        pass
Пример #6
0
def install(c, is_install=True):
    """
    Install Ki-nTree dependencies
    """

    if is_install:
        cprint('[MAIN]\tInstalling required dependencies')
        c.run('pip install -U wheel', hide='out')
    else:
        cprint('[MAIN]\tUpdating required dependencies')
    c.run('pip install -U -r requirements.txt', hide='out')

    if is_install:
        cprint('[MAIN]\tInstalling optional dependencies')
        try:
            c.run('pip install -U python-Levenshtein', hide=True)
        except UnexpectedExit:
            cprint('\n[INFO]\tFailed to install python-Levenshtein...\t'
                   'You may be missing python3.x-dev')
Пример #7
0
def make_python_badge(c):
    """
    Make badge for supported versions of Python
    """

    cprint('[MAIN]\tInstall pybadges')
    c.run('pip install pybadges pip-autoremove', hide=True)
    cprint('[MAIN]\tCreate badge')
    c.run(
        'python -m pybadges --left-text="Python" --right-text="3.7 - 3.9" '
        '--whole-link="https://www.python.org/" --browser --embed-logo '
        '--logo="https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/python.svg"'
    )
    cprint('[MAIN]\tUninstall pybadges')
    c.run('pip-autoremove pybadges -y', hide=True)
    c.run('pip uninstall pip-autoremove -y', hide=True)
Пример #8
0
def pretty_test_print(message: str):
    cprint(message.ljust(65), end='')
Пример #9
0
settings.set_kicad_enable_flag(True, save=True)
# Load user configuration files
settings.load_user_config()
# Set path to test libraries
test_library_path = os.path.join(settings.PROJECT_DIR, 'tests', 'TEST.lib')
symbol_libraries_test_path = os.path.join(settings.PROJECT_DIR, 'tests',
                                          'files', 'SYMBOLS')
footprint_libraries_test_path = os.path.join(settings.PROJECT_DIR, 'tests',
                                             'files', 'FOOTPRINTS', '')
# Disable Digi-Key API logging
digikey_api.disable_api_logger()

# Test Digi-Key API
pretty_test_print('[MAIN]\tDigi-Key API Test')
if not digikey_api.test_api_connect(check_content=True):
    cprint('[ FAIL ]')
    cprint('[INFO]\tFailed to get Digi-Key API token, aborting.')
    sys.exit(-1)
else:
    cprint('[ PASS ]')

# Test Mouser API
pretty_test_print('[MAIN]\tMouser API Test')
if not mouser_api.test_api():
    cprint('[ FAIL ]')
    sys.exit(-1)
else:
    cprint('[ PASS ]')

# Test LCSC API
pretty_test_print('[MAIN]\tLCSC API Test')
Пример #10
0
def pretty_test_print(message: str):
    message = message.ljust(65)
    cprint(message, end='')
Пример #11
0
# Enable InvenTree
settings.set_inventree_enable_flag(True, save=True)
# Enable KiCad
settings.set_kicad_enable_flag(True, save=True)
# Load user configuration files
settings.load_user_config()
# Set path to test libraries
test_library_path = os.path.join(settings.PROJECT_DIR, 'tests', 'TEST.lib')
symbol_libraries_test_path = os.path.join(settings.PROJECT_DIR, 'tests',
                                          'files', 'SYMBOLS')
footprint_libraries_test_path = os.path.join(settings.PROJECT_DIR, 'tests',
                                             'files', 'FOOTPRINTS', '')
# Disable API logging
disable_digikey_api_logger()
if not test_digikey_api_connect():
    cprint('[INFO]\tFailed to get Digi-Key API token, aborting.')
    sys.exit(-1)

# Pretty test printing


def pretty_test_print(message: str):
    message = message.ljust(65)
    cprint(message, end='')


# Check result


def check_result(status: str, new_part: bool) -> bool:
    # Build result