From patchwork Thu Mar 31 13:23:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max X-Patchwork-Id: 604133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 3qbQFl3Gg7z9ryW for ; Fri, 1 Apr 2016 00:23:55 +1100 (AEDT) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id A13961C511; Thu, 31 Mar 2016 13:23:52 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.sysmocom.de (mail.sysmocom.de [IPv6:2a01:4f8:191:444c::2:4]) by lists.osmocom.org (Postfix) with ESMTP id 2F0461C501 for ; Thu, 31 Mar 2016 13:23:49 +0000 (UTC) Received: from mail.sysmocom.de (mail.sysmocom.de [144.76.43.93]) by mail.sysmocom.de (Postfix) with ESMTP id 46C931963DA; Thu, 31 Mar 2016 13:23:19 +0000 (UTC) Received: from pbell.local (ip5b418565.dynamic.kabel-deutschland.de [91.65.133.101]) by mail.sysmocom.de (Postfix) with ESMTPSA id F35101963D9; Thu, 31 Mar 2016 13:23:17 +0000 (UTC) From: msuraev@sysmocom.de To: openbsc@lists.osmocom.org Subject: [PATCH] Add optional copy_files attribute Date: Thu, 31 Mar 2016 15:23:16 +0200 Message-Id: <1459430596-9066-1-git-send-email-msuraev@sysmocom.de> X-Mailer: git-send-email 2.8.0 X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Max This allows to specify additional files which shall be copied into temporary directory where tests are executed. --- osmopy/osmotestconfig.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/osmopy/osmotestconfig.py b/osmopy/osmotestconfig.py index b020d86..1e72d4b 100644 --- a/osmopy/osmotestconfig.py +++ b/osmopy/osmotestconfig.py @@ -18,20 +18,20 @@ import os import os.path import time import sys -import tempfile +import tempfile, shutil import osmopy.obscvty as obscvty import osmopy.osmoutil as osmoutil # Return true iff all the tests for the given config pass -def test_config(app_desc, config, tmpdir, verbose=True): +def test_config(app_desc, config, tmpdir, copy_files, verbose=True): try: err = 0 if test_config_atest(app_desc, config, verify_doc, verbose)[0] > 0: err += 1 - newconfig = copy_config(tmpdir, config) + newconfig = copy_config(tmpdir, config, copy_files) if test_config_atest(app_desc, newconfig, write_config, verbose) > 0: err += 1 @@ -73,7 +73,7 @@ def test_config_atest(app_desc, config, run_test, verbose=True): return ret -def copy_config(dirname, config): +def copy_config(dirname, config, copy_files): try: os.stat(dirname) except OSError: @@ -82,6 +82,9 @@ def copy_config(dirname, config): remove_tmpdir(dirname) os.mkdir(dirname) + for f in copy_files: + shutil.copy(f, dirname) + prefix = os.path.basename(config) tmpfile = tempfile.NamedTemporaryFile( dir=dirname, prefix=prefix, delete=False) @@ -155,9 +158,10 @@ def check_configs_tested(basedir, app_configs, ignore_configs): def test_all_apps(apps, app_configs, tmpdir="writtenconfig", verbose=True, - confpath=".", rmtmp=False, ignore_configs=[]): + confpath=".", rmtmp=False, ignore_configs=[], copy_files=[]): check_configs_tested("doc/examples/", app_configs, ignore_configs) errors = 0 + for app in apps: if not app_exists(app): print >> sys.stderr, "Skipping app %s (not found)" % app[1] @@ -166,7 +170,7 @@ def test_all_apps(apps, app_configs, tmpdir="writtenconfig", verbose=True, configs = app_configs[app[3]] for config in configs: config = os.path.join(confpath, config) - errors |= test_config(app, config, tmpdir, verbose) + errors |= test_config(app, config, tmpdir, copy_files, verbose) if rmtmp or not errors: remove_tmpdir(tmpdir) @@ -203,10 +207,12 @@ if __name__ == '__main__': apps = osmoappdesc.apps configs = osmoappdesc.app_configs ignores = getattr(osmoappdesc, 'ignore_configs', []) + copycat = getattr(osmoappdesc, 'copy_files', []) if args.e1nitb: configs['nitb'].extend(osmoappdesc.nitb_e1_configs) os.chdir(workdir) sys.exit(test_all_apps(apps, configs, ignore_configs=ignores, - confpath=confpath, verbose=args.verbose)) + confpath=confpath, copy_files=copycat, + verbose=args.verbose))