Пример #1
0
 def codefile_rep_chinese(self, path):
     file = CodeFile(path)
     chinese = file.list_chinese()
     file.replace_tag()
     # for s in chinese:
     #     print(s)
     return chinese
Пример #2
0
 def test_actor_parameter_names( self ):
     '''Check the parameters dictionary contains the correct names'''
     filepath = path.abspath(path.join(PATH_TO_SRC_DIR, 'scipysim','actors','math','trig','DTSinGenerator.py'))
     c = CodeFile( filepath )
     # arguments should contain this:
     # self, out, amplitude=1.0, freq=0.01, phi=0.0, simulation_length=100
     params = c.get_default_parameters()
     for name in ['out', 'amplitude', 'freq', 'phi', 'simulation_length']:
         self.assertTrue(name in params)
Пример #3
0
 def test_actor_parameter_defaults(self):
     '''Check the parameters dictionary contains the correct default arguments'''
     filepath = path.abspath(path.join(PATH_TO_SRC_DIR, 'scipysim','actors','math','trig','DTSinGenerator.py'))
     c = CodeFile( filepath )
     # arguments should contain this:
     # self, out, amplitude=1.0, freq=0.01, phi=0.0, simulation_length=100
     params = c.get_default_parameters()
     for name, value in [('out', None), ('amplitude',1.0), ('freq',0.01), ('phi',0.0), ('simulation_length',100)]:
         self.assertEquals(params[name], value)
Пример #4
0
    def test_connect_nodes(self):
        '''Connect nodes together'''
        g = Graph()
        source_node = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'DTSinGenerator.py' ), 'DTSinGenerator' ))
        gain = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'proportional.py'), 'Proportional'))

        g.add(source_node)
        g.add(gain)

        chan = source_node.output_channels[0]
        g.connect(chan, gain)
Пример #5
0
    def test_run(self):
        '''Test execution'''
        g = Graph()
        source_node = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'DTSinGenerator.py' ), 'DTSinGenerator' ))
        gain = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'proportional.py'), 'Proportional'))
        
        g.add(source_node)
        g.add(gain)

        # could connect this up to a file writer to unittest the output (io.TextWriter)
        
        g.connect(source_node.output_channels[0], gain)
        self.assertTrue(g.ready())
        g.run()
Пример #6
0
    def test_verify(self):
        '''Verify that all inputs are connected'''
        g = Graph()
        source_node = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'DTSinGenerator.py' ), 'DTSinGenerator' ))
        gain = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'proportional.py'), 'Proportional'))

        g.add(source_node)
        g.add(gain)
        
        gain.params['gain'] = 10

        chan = source_node.output_channels[0]
        g.connect(chan, gain)
        self.assertTrue(g.ready())
Пример #7
0
 def test_remove_node( self ):
     '''Add then remove a node to a graph'''
     g = Graph()
     node = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'sin.py' ) ))
     g.add(node)
     g.remove(node)
     self.assertFalse(node in g)
Пример #8
0
 def test_node_makes_output_chans(self):
     '''Nodes should create output channels'''
     n = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'DTSinGenerator.py' ), 'DTSinGenerator' ))
     self.assertTrue(isinstance( n.output_channels, list))
     self.assertEquals(len(n.output_channels), 1)
     self.assertTrue(isinstance(n.output_channels[0], Channel))
     self.assertEquals(n.output_channels[0].domain, 'DT')
Пример #9
0
 def test_node_has_channels(self):
     '''A node should have a list of both input and output channels
     (possibly empty)'''
     
     n = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'sin.py' ) ))
     self.assertTrue(isinstance( n.output_channels, list))
     self.assertEquals(len(n.input_channels), 0)
Пример #10
0
 def test_multiple_instances(self):
     '''Ensure parameter changing is node specific.'''
     c = CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'sin.py' ) )
     n1 = Node(c)
     n2 = Node(c)
     self.assertEquals(n1.params, n2.params)
     n1.params['freq'] = 9999
     self.assertNotEquals(n1.params, n2.params)
Пример #11
0
 def test_add_node( self ):
     '''Add a node to a graph'''
     g = Graph()
     cf = CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'sin.py' ) )
     self.assertEquals(cf.name, 'Sin')
     node = Node(cf)
     g.add(node)
     self.assertTrue(node in g)
Пример #12
0
    def test_verify_fails(self):
        '''Create a model with an unfilled input channel'''
        g = Graph()
        
        gain = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'proportional.py'), 'Proportional'))
        g.add(gain)
        gain.params['gain'] = 10

        self.assertFalse(g.ready())        
Пример #13
0
def fill_tree(tree, directory):
    '''Parse a directory and add to an existing tree.
    Return a dictionary of the tree id: CodeFile'''
    codefiles = {}
    for file_tuple in os.walk(directory):
        '''The tuples contains:
            [0] - The path
            [1] - Subdirectories
            [2] - Files
        '''
        # Find out where we are in the tree
        parent_node = os.path.dirname(os.path.relpath(file_tuple[0],
                                                      directory))
        current_node = os.path.relpath(file_tuple[0], directory)
        if current_node is ".": current_node = ""
        logging.debug("Current node is: <%s>, Parent node is: <%s>" %
                      (current_node, parent_node))

        # Search for interesting files
        python_file_regex = re.compile("^(?!tests?).*[^_]\.py$", re.IGNORECASE)
        files = filter(python_file_regex.search, file_tuple[2])
        logging.info("Under the %s directory are %d files: \n%s" %
                     (os.path.basename(file_tuple[0]), len(files), files))

        logging.debug("Add the files in directory to the current node")
        for file in files:
            logging.debug("Inserting %s underneath an existing node" % file)
            node = os.path.relpath(os.path.join(file_tuple[0], file),
                                   directory)
            codefiles[node] = CodeFile(os.path.join(file_tuple[0], file))
            tree.insert(current_node, 'end', node, text=file, tags=('node'))

            logging.debug("Inserted '%s' node under '%s' with ID: '%s'" %
                          (file, current_node, node))
            tree.set(node, 'ins', codefiles[node].num_inputs)
            tree.set(node, 'outs', codefiles[node].num_outputs)

        # Must add the (sub)directories to the tree as nodes under the current node.
        for subdir in file_tuple[1]:
            '''
            subdir is going to be a string like "trig"
            but the tree id will be math/trig
            '''
            node = os.path.relpath(os.path.join(file_tuple[0], subdir),
                                   directory)
            logging.debug("Child node is: <%s>" % node)
            tree.insert(current_node,
                        'end',
                        node,
                        text=subdir.title(),
                        tags=('dir'))
    return codefiles
Пример #14
0
 def test_create_node(self):
     '''test creation of a blank node'''
     n = Node(CodeFile( get_source( 'scipysim', 'actors', 'math', 'trig', 'sin.py' ) ))
Пример #15
0
 def test_codefile_import(self):
     filepath = path.abspath(path.join(PATH_TO_SRC_DIR, 'scipysim','actors','math','trig','DTSinGenerator.py'))
     c = CodeFile( filepath )
     self.assertEquals(c.get_import(), 'from scipysim.actors.math.trig.DTSinGenerator import DTSinGenerator')
Пример #16
0
 def codefile_list_chinese(self, path):
     file = CodeFile(path)
     ret = file.list_chinese()
     return ret
Пример #17
0
 def translate_file(self, path):
     file = CodeFile(path)
     ret = file.translate_cht()
     pass