def testModuleDerivationPass(self): # missing exec in derived is okay text = text0 + ''' base: R(base=1) x: 2 $out: x simulate(base): x: R(1:5) ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['command'], 'base=1') text = text0 + ''' base: R(base=1) x: 2 $out: x simulate(base): R(base=2) x: R(1:5) ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['command'], 'base=2') # Derive from one of compact modules text = text0 + ''' normal, t: R(), R() n: 1000 @normal: y: 5 n: 6 $x: x simulate(normal): mu: 1 ''' res = DSC_Script(text) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('n', [6]), ('y', [5]), ('mu', [1])])
def testFilterPass(self): text = text0 + ''' simulate, t: R(), R() n: 100, 200, 300, 400, 500 k: 0, 1 @FILTER: simulate: (n <= 300 and k = 0) or (n > 300 and k = 1) t: n = 500 $x: x ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['input_filter'], '(_n <= 300 and _k == 0) or (_n > 300 and _k == 1)') text = text0 + ''' simulate, t: R(), R() n: 100, 200, 300, 400, 500 k: 0, 1 @FILTER: (n in [100,200,300] and k = 0) $x: x ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['input_filter'], '(_n in (100,200,300) and _k == 0)') text = text0 + ''' simulate, t: R(), R() n: 100, 200, 300, 400, 500 k: 0, 1 @FILTER: *: n in [100,200,300] t: n = 300 $x: x ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['input_filter'], '(_n in (100,200,300))')
def testBasicSyntaxPass(self): '''basic syntax parser success''' # exec decoration res = DSC_Script(text3) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [1]), ('y', [2])]) # alias for specific module, both syntax supported res = DSC_Script(text6) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [1]), ('y', [2])]) self.assertEqual(list(res.modules['simulate'].plugin.alias_map.items()), [('x', 'x_1')]) res = DSC_Script(text7) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [1]), ('y', [2])]) self.assertEqual(list(res.modules['simulate'].plugin.alias_map.items()), [('x', 'x_1')]) res = DSC_Script(text8) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [1]), ('y', [2])]) self.assertEqual(list(res.modules['simulate'].plugin.alias_map.items()), [('x', 'x_1')]) # use global variable res = DSC_Script(text11) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [2]), ('y', [2])]) res = DSC_Script(text12) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('x', [4,3,2,1]), ('y', [2])]) # alias partial list / dict res = DSC_Script(text13) self.assertEqual(list(res.modules['simulate'].plugin.dump()['container_variables'].items()), [('x', [None, 'xvar']), ('y', [None, 'yy'])]) # filter decorator res = DSC_Script(text14) self.assertEqual(res.modules['simulate'].dump()['input_filter'], '(_x < 3)')
def testQuotedKeywords(self): text = text0 + ''' simulate: R() K: TRUE, FALSE, NULL $out: K ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['input']['K'], ['TRUE', 'FALSE', 'NULL']) text = text0 + ''' simulate: Python() K: 'TRUE', 'FALSE', 'NULL' $out: K ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['input']['K'], ["'TRUE'", "'FALSE'", "'NULL'"])
def testConfOperatorPass(self): text = text0 + ''' simulate: R() $x: x @CONF: work_dir = /tmp, exec_path = /tmp ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].path, ['/tmp']) text = text0 + ''' simulate: R() $x: x @CONF: work_dir = /tmp, exec_path = (/tmp, ~/tmp), lib_path = ./, R_libs = (ashr@stephenslab/ashr (>=2.2.7), psych) ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].path, ['/tmp', '~/tmp']) self.assertEqual(res.modules['simulate'].exe['header'], 'library(ashr)\nlibrary(psych)')
def testFileOperatorPass(self): # file() operator text = text0 + ''' simulate: R() data: file(.txt) $out: n ''' res = DSC_Script(text) self.assertEqual(res.modules['simulate'].dump()['plugin_status']['temp_file'], ['data <- paste0(${_output[0]:nr}, ".data.txt")'])
def testParenthesisOperatorPass(self): # () operator # FIXME: likely wrong here? text = text0 + ''' simulate: R() (n,p): (1,2), (5,6) $x: x ''' res = DSC_Script(text) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('n', [1, 5]), ('p', [2, 6])]) # R{} operator text = text0 + ''' simulate: R() (n,p): R{list(c(1,2), c(5,6))} $x: x ''' res = DSC_Script(text) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('n', [1, 5]), ('p', [2, 6])])
def testModuleVariablesPass(self): # module input and output can have same name text = text0 + ''' simulate: R() n: $n $n: n ''' res = DSC_Script(text) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('n', ['$n'])]) self.assertEqual(res.modules['simulate'].dump()['output_variables'], {'n':'n'})
def testGroupedParametersPass(self): # grouped parameters text = text0 + ''' simulate: R() (n,p): (1,2), (5,6) a,b: (3,4) t: 5 $x: x ''' res = DSC_Script(text) self.assertEqual(list(res.modules['simulate'].dump()['input'].items()), [('n', [1, 5]), ('p', [2, 6]), ('a', [3]), ('b', [4]), ('t', [5])])