diff mbox

Add optional copy_files attribute

Message ID 1459430596-9066-1-git-send-email-msuraev@sysmocom.de
State New
Headers show

Commit Message

Max March 31, 2016, 1:23 p.m. UTC
From: Max <msuraev@sysmocom.de>

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(-)

Comments

Holger Freyther March 31, 2016, 2:19 p.m. UTC | #1
> On 31 Mar 2016, at 15:23, msuraev@sysmocom.de wrote:
> 
> From: Max <msuraev@sysmocom.de>
> 
> This allows to specify additional files which shall be copied into
> temporary directory where tests are executed.

when we chatted I had something like this in make

make_tmp_dir
copy_recursively(orig, tmp_dir)
run(tmp_dir/cfg_file)

was your approach more simple?
Max April 6, 2016, 3:20 p.m. UTC | #2
On 03/31/2016 04:19 PM, Holger Freyther wrote:
>> On 31 Mar 2016, at 15:23, msuraev@sysmocom.de wrote:
>>
>> From: Max <msuraev@sysmocom.de>
>>
>> This allows to specify additional files which shall be copied into
>> temporary directory where tests are executed.
> when we chatted I had something like this in make
>
> make_tmp_dir
> copy_recursively(orig, tmp_dir)
> run(tmp_dir/cfg_file)
>
> was your approach more simple?
>
Yes - instead of trying to re-create directory structure (which would
make test runner unnecessary complex) I simply copy necessary additional
configs explicitly. Using extension other than .cfg makes sure that they
won't be copied (this one is recursive already btw) by config tester.
Holger Freyther April 6, 2016, 7:03 p.m. UTC | #3
> On 06 Apr 2016, at 17:20, Max <msuraev@sysmocom.de> wrote:
> 
> 


>> was your approach more simple?
>> 
> Yes - instead of trying to re-create directory structure (which would
> make test runner unnecessary complex) I simply copy necessary additional
> configs explicitly. Using extension other than .cfg makes sure that they
> won't be copied (this one is recursive already btw) by config tester.

yes, but the code seems to be more involved than:

	shutil.copytree

Can't we simplify the code by using this routine instead of having an extra list of files to copy?
Holger Freyther April 12, 2016, 2:06 p.m. UTC | #4
> On 06 Apr 2016, at 15:03, Holger Freyther <holger@freyther.de> wrote:
> 
> 

Max,


> yes, but the code seems to be more involved than:
> 
> 	shutil.copytree
> 
> Can't we simplify the code by using this routine instead of having an extra list of files to copy?

is this still relevant? Or old because of the other patch?

holger
Max April 12, 2016, 2:24 p.m. UTC | #5
No, it's superseded by another patch.

On 04/12/2016 04:06 PM, Holger Freyther wrote:
>> On 06 Apr 2016, at 15:03, Holger Freyther <holger@freyther.de> wrote:
>>
>>
> Max,
>
>
>> yes, but the code seems to be more involved than:
>>
>> 	shutil.copytree
>>
>> Can't we simplify the code by using this routine instead of having an extra list of files to copy?
> is this still relevant? Or old because of the other patch?
>
> holger
diff mbox

Patch

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))