Skip to content

Commit

Permalink
Added kicad2step simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Jun 2, 2022
1 parent 77bd826 commit 5216b1e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 41 additions & 0 deletions tests/kicad2step/test_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Salvador E. Tropea
# Copyright (c) 2022 Instituto Nacional de Tecnologïa Industrial
# License: Apache 2.0
# Project: KiAuto (formerly kicad-automation-scripts)
"""
Tests for kicad2step
For debug information use:
pytest-3 --log-cli-level debug
"""

import os
import sys
import logging
# Look for the 'utils' module from where the script is running
script_dir = os.path.dirname(os.path.abspath(__file__))
prev_dir = os.path.dirname(script_dir)
sys.path.insert(0, prev_dir)
# Utils import
from utils import context
sys.path.insert(0, os.path.dirname(prev_dir))
from kiauto.misc import (PCBNEW_CFG_PRESENT, NO_PCB, WRONG_PCB_NAME, WRONG_ARGUMENTS, CORRUPTED_PCB)

PROG = 'kicad2step_do'


def test_kicad2step_1(test_dir):
fname = 'good.step'
fdir = os.path.join(test_dir, 'STEP_1')
ctx = context.TestContext(test_dir, 'STEP_1', 'good-project')
os.environ['KIPRJMOD'] = os.path.dirname(ctx.board_file)
cmd = [PROG, '-vvv', '-o', fname, '-d', fdir, '--subst-models']
ffname = os.path.join(fdir, fname)
if os.path.isfile(ffname):
os.remove(ffname)
ctx.run(cmd, no_dir=True)
del os.environ['KIPRJMOD']
ctx.expect_out_file(fname)
ctx.clean_up()
5 changes: 3 additions & 2 deletions tests/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ def read(fd):
TestContext.pty_data += data
return data

def run(self, cmd, ret_val=None, extra=None, use_a_tty=False, filename=None, ignore_ret=False):
def run(self, cmd, ret_val=None, extra=None, use_a_tty=False, filename=None, ignore_ret=False, no_dir=False):
logging.debug('Running '+self.test_name)
# Change the command to be local and add the board and output arguments
cmd[0] = os.path.abspath(os.path.dirname(os.path.abspath(__file__))+'/../../src/'+cmd[0])
cmd = [COVERAGE_SCRIPT, 'run', '-a']+cmd
cmd.append(filename if filename else self.board_file)
cmd.append(self.output_dir)
if not no_dir:
cmd.append(self.output_dir)
if extra is not None:
cmd = cmd+extra
logging.debug(usable_cmd(cmd))
Expand Down

0 comments on commit 5216b1e

Please sign in to comment.