class CheckpointTestCase(unittest.TestCase): def setUp(self): self.nest = Nest() self.nest.add('list', [[]], create_dir=False) self.w = scons.SConsWrap(self.nest) self.w.add('level1', range(2)) self.w.add('level2', (1, 2, 3)) def test_pop_with_name(self): w = self.w @w.add_target() def key_file(outdir, c): c['list'].append(c['level2']) return True @w.add_target() def assertion_during(outdir, c): self.assertTrue(c['key_file']) self.assertTrue('level2' in c) return True n2 = w.nest w.pop('level1') n1 = w.nest # Want to make sure nested level checkpoints are popped off as well self.assertEqual(len(w.checkpoints), 0) # Make sure we have the right nest now self.assertTrue(self.nest is n1) self.assertFalse(self.nest is n2) @w.add_target() def assertion_after(outdir, c): self.assertFalse('key_file' in c) self.assertEqual(6, len(c['list'])) self.assertFalse('level2' in c) def test_pop_last(self): w = self.w w.pop() # This time, there should be one checkpoint left self.assertEqual(len(w.checkpoints), 1) self.assertTrue('level1' in w.checkpoints) @w.add_target() def assertion_after(outdir, c): self.assertFalse('level2' in c) self.assertTrue('level1' in c) def test_pop_missing(self): self.assertRaises(KeyError, self.w.pop, 'missing_key') self.assertEqual(['level1', 'level2'], sorted(self.w.checkpoints.keys()))
def setUp(self): # Default output will a return a reference, which means consecutive # calls to .Clone will return references to the same dictionary. Use # OutputCopyingMock to avoid clobbering mutation. self.env = OutputCopyingMock(['Clone'], name='MockSConsEnvironment') self.env.Clone.return_value = {} self.func_mock = mock.Mock('__call__', name='func_mock') self.func_mock.__name__ = 'func_mock' self.n = Nest() self.n.add('item', [1, 2])
class AddTargetWithEnvTestCase(unittest.TestCase): def setUp(self): # Default output will a return a reference, which means consecutive # calls to .Clone will return references to the same dictionary. Use # OutputCopyingMock to avoid clobbering mutation. self.env = OutputCopyingMock(['Clone'], name='MockSConsEnvironment') self.env.Clone.return_value = {} self.func_mock = mock.Mock('__call__', name='func_mock') self.func_mock.__name__ = 'func_mock' self.n = Nest() self.n.add('item', [1, 2]) def test_basic(self): w = scons.SConsWrap(self.n) w.add_target_with_env(self.env)(self.func_mock) # Clone is be called with no arguments self.env.Clone.assert_called_with() calls = [mock.call({'item': 1, 'OUTDIR': './1'}, './1', {'item': 1, 'OUTDIR': '1'}), mock.call({'item': 2, 'OUTDIR': './2'}, './2', {'item': 2, 'OUTDIR': '2'})] self.func_mock.assert_has_calls(calls)
def setUp(self): self.nest = Nest() self.nest.add('list', [[]], create_dir=False) self.w = scons.SConsWrap(self.nest) self.w.add('level1', range(2)) self.w.add('level2', (1, 2, 3))
from nestly import Nest from nestly.scons import SConsWrap, name_targets import os import os.path import numpy import appconfig config = appconfig.read('config.yaml') # Base folder nest = Nest() wrap = SConsWrap( nest, os.path.join(config['cluster']['folder'], config['cluster']['algorithms']['srmcl']['folder'])) env = Environment(ENV=os.environ) # Used for resolving what type of execution environment will be used. exec_env = appconfig.ExecutionEnvironment( ARGUMENTS, supported_env=['pbs', 'sge', 'local']) # Variation # don't include root as we don't want it embedded in this nest hierarchy hic_paths = appconfig.get_precedents(config['map_folder'], config['hic2ctg'], prepend_root=False, tips_only=True) wrap.add('hic_path', hic_paths)
#!/usr/bin/env python import glob import os import os.path from nestly import Nest, stripext wd = os.getcwd() startersdir = os.path.join(wd, "starters") winedir = os.path.join(wd, "wine") mainsdir = os.path.join(wd, "mains") nest = Nest() bn = os.path.basename # Start by mirroring the two directory levels in startersdir, and name those # directories "ethnicity" and "dietary". nest.add('ethnicity', glob.glob(os.path.join(startersdir, '*')), label_func=bn) # In the `dietary` key, the anonymous function `lambda ...` chooses as values # names of directories the current `ethnicity` directory nest.add('dietary', lambda c: glob.glob(os.path.join(c['ethnicity'], '*')), label_func=bn) ## Now get all of the starters. nest.add('starter', lambda c: glob.glob(os.path.join(c['dietary'], '*')), label_func=stripext) ## Then get the corresponding mains. nest.add('main', lambda c: [os.path.join(mainsdir, bn(c['ethnicity']) + "_stirfry.txt")],
#!/usr/bin/env python import glob import math import os import os.path from nestly import Nest wd = os.getcwd() input_dir = os.path.join(wd, 'inputs') nest = Nest() # Simplest case: Levels are added with a name and an iterable nest.add('strategy', ('exhaustive', 'approximate')) # Sometimes it's useful to add multiple keys to the nest in one operation, e.g. # for grouping related data. # This can be done by passing an iterable of dictionaries to the `Nest.add` call, # each containing at least the named key, along with the `update=True` flag. # # Here, 'run_count' is the named key, and will be used to create a directory in the nest, # and the value of 'power' will be added to each control dictionary as well. nest.add('run_count', [{'run_count': 10**i, 'power': i} for i in range(3)], update=True) # label_func can be used to generate a meaningful name. Here, it strips the all # but the file name from the file path nest.add('input_file', glob.glob(os.path.join(input_dir, 'file*')), label_func=os.path.basename)