Ejemplo n.º 1
0
 def test_multi_aliased_from_import_block(self):
     sut = PythonDeclaration(
         "from biicode.common.edition import Parser as pepe, Counter as cont"
     )
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals([("Parser", "pepe"), ("Counter", "cont")],
                       sut.python_import().names)
Ejemplo n.º 2
0
 def test_normalize_import_with_alias(self):
     sut = PythonDeclaration("import myblock as block")
     result = sut.normalize(
         ['testuser/block/__init__.py', 'testuser/block/myblock.py'])
     self.assertEquals(
         PythonDeclaration("import testuser.block.myblock as block"),
         result)
Ejemplo n.º 3
0
 def test_complex_normalize_with_alias(self):
     sut = PythonDeclaration("from myblock import Parser as Hell")
     result = sut.normalize(
         ['testuser/block/__init__.py', 'testuser/block/myblock.py'])
     self.assertEquals(
         PythonDeclaration(
             "from testuser.block.myblock import Parser as Hell"), result)
Ejemplo n.º 4
0
 def test_init_match(self):
     sut = PythonDeclaration("import biicode.common.edition")
     block_cell_names = set([
         BlockCellName("biicode/common/__init__.py"),
         BlockCellName("biicode/common/edition.py")
     ])
     self.assertEquals(block_cell_names, sut.match(block_cell_names))
 def test_multi_init_match(self):
     sut = PythonDeclaration("import biicode.common.edition")
     block_cell_names = set([BlockCellName("biicode/common/__init__.py"),
                             BlockCellName("biicode/common/test/__init__.py"),
                             BlockCellName("biicode/common/edition.py")])
     expected = set([BlockCellName("biicode/common/__init__.py"),
                     BlockCellName("biicode/common/edition.py")])
     self.assertEquals(expected, sut.match(block_cell_names))
    def test_simple_match_relative(self):
        sut = PythonDeclaration("from edition import *")

        block_cell_names = set([BlockCellName("biicode/common/edition.py"),
                                BlockCellName("biicode/common/jarl.py")])

        from_block_cell_name = BlockCellName("biicode/common/main.py")
        self.assertEquals(set([BlockCellName("biicode/common/edition.py")]),
                          sut.match(block_cell_names, from_block_cell_name))
Ejemplo n.º 7
0
    def test_declarations(self):
        d1 = CPPDeclaration('path/to/file.h')
        s = d1.serialize()
        d2 = CPPDeclaration.deserialize(s)
        self.assertEqual(d1, d2)

        d1 = PythonDeclaration("import sys")
        s = d1.serialize()
        d2 = PythonDeclaration.deserialize(s)
        self.assertEqual(d1, d2)
Ejemplo n.º 8
0
    def test_simple_match_relative_in_different_block(self):
        sut = PythonDeclaration("from edition import *")

        block_cell_names = set([
            BlockCellName("biicode/parsing/edition.py"),
            BlockCellName("biicode/parsing/jarl.py")
        ])

        from_block_cell_name = BlockCellName("biicode/common/main.py")
        self.assertEquals(set(),
                          sut.match(block_cell_names, from_block_cell_name))
    def test_multi_init_levels_match_relative_import(self):
        sut = PythonDeclaration("import name")

        block_cell_names = set([BlockCellName("biicode/common/__init__.py"),
                                BlockCellName("biicode/common/test/__init__.py"),
                                BlockCellName("biicode/common/test/name.py"),
                                BlockCellName("biicode/common/edition.py")])

        expected = set([BlockCellName("biicode/common/__init__.py"),
                        BlockCellName("biicode/common/test/__init__.py"),
                        BlockCellName("biicode/common/test/name.py")])

        self.assertEquals(expected, sut.match(block_cell_names,
                                              BlockCellName("biicode/common/test/name.py")))
Ejemplo n.º 10
0
    def test_multi_init_levels_match(self):
        sut = PythonDeclaration("import biicode.common.test.name")
        block_cell_names = set([
            BlockCellName("biicode/common/__init__.py"),
            BlockCellName("biicode/common/test/__init__.py"),
            BlockCellName("biicode/common/test/name.py"),
            BlockCellName("biicode/common/edition.py")
        ])

        expected = set([
            BlockCellName("biicode/common/__init__.py"),
            BlockCellName("biicode/common/test/__init__.py"),
            BlockCellName("biicode/common/test/name.py")
        ])
        self.assertEquals(expected, sut.match(block_cell_names))
Ejemplo n.º 11
0
    def test_declarations(self):
        d1 = CPPDeclaration('path/to/file.h')
        s = d1.serialize()
        d2 = CPPDeclaration.deserialize(s)
        self.assertEqual(d1, d2)

        d1 = PythonDeclaration("import sys")
        s = d1.serialize()
        d2 = PythonDeclaration.deserialize(s)
        self.assertEqual(d1, d2)
Ejemplo n.º 12
0
    def test_python_c_include(self):
        code = r'''
import biipyc
import my_block
lib = link_clib("user/block/test.h")
some_var = test("user/block/cosa.h")
value = 3
libd = biipyc.link_clib("user/block/test2.h")'''

        py = PythonParser()
        py.parse(code)
        obtained_explicit_decs = py.explicit_declarations
        expected_explicit_decs = [CPPDeclaration("user/block/test.h"),
                                  CPPDeclaration("user/block/test2.h"),
                                  PythonDeclaration("import my_block"),
                                  PythonDeclaration("import biipyc")]

        self.assertItemsEqual(expected_explicit_decs, obtained_explicit_decs)
        self.assertTrue(py.has_main_function())
 def test_simple_match(self):
     sut = PythonDeclaration("import biicode.common.edition")
     block_cell_names = set([BlockCellName("biicode/common/edition.py"),
                             BlockCellName("biicode/common/jarl.py")])
     self.assertEquals(set([BlockCellName("biicode/common/edition.py")]),
                       sut.match(block_cell_names))
 def test_from_import_error(self):
     sut = PythonDeclaration("from biicode.common.edition impor Parser")
     self.assertIsNone(sut.block())
 def test_multi_aliased_from_import_block(self):
     sut = PythonDeclaration("from biicode.common.edition import Parser as pepe, Counter as cont")
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals([("Parser", "pepe"), ("Counter", "cont")], sut.python_import().names)
 def test_aliased_general_import_block(self):
     sut = PythonDeclaration("import biicode.common.edition as pepe")
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals(None, sut.python_import().names)
 def test_from_import_all(self):
     sut = PythonDeclaration("from biicode.common.edition import *")
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals([("*", None)], sut.python_import().names)
Ejemplo n.º 18
0
 def test_aliased_general_import_block(self):
     sut = PythonDeclaration("import biicode.common.edition as pepe")
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals(None, sut.python_import().names)
Ejemplo n.º 19
0
 def test_match_composed_system(self):
     sut = PythonDeclaration("import xml.dom.domreg")
     validator = self.generate_python_sys_libs()
     self.assertEquals(set(["xml/dom/domreg.py"]),
                       sut.match_system(validator))
 def test_normalize_import_with_alias(self):
     sut = PythonDeclaration("import myblock as block")
     result = sut.normalize(['testuser/block/__init__.py', 'testuser/block/myblock.py'])
     self.assertEquals(PythonDeclaration("import testuser.block.myblock as block"), result)
 def test_normalize_multi_dir(self):
     sut = PythonDeclaration("import biipyc")
     result = sut.normalize(['testuser1/pyc/pythondynlibs/biipyc.py'])
     self.assertEquals(PythonDeclaration("import testuser1.pyc.pythondynlibs.biipyc as biipyc"),
                       result)
 def test_match_system_inexistent(self):
     sut = PythonDeclaration("import reee")
     validator = self.generate_python_sys_libs()
     self.assertEquals(set([]), sut.match_system(validator))
 def test_match_composed_system(self):
     sut = PythonDeclaration("import xml.dom.domreg")
     validator = self.generate_python_sys_libs()
     self.assertEquals(set(["xml/dom/domreg.py"]), sut.match_system(validator))
Ejemplo n.º 24
0
 def test_normalize_composed_import(self):
     sut = PythonDeclaration("import     biicode.common.edition.parsing")
     result = sut.normalize(['biicode/common/edition/parsing.py'])
     self.assertEquals(
         PythonDeclaration("import biicode.common.edition.parsing"), result)
Ejemplo n.º 25
0
 def test_from_import_block(self):
     sut = PythonDeclaration("from biicode.common.edition import Parser")
     self.assertEquals("biicode/common", sut.block())
     self.assertEquals([('Parser', None)], sut.python_import().names)
Ejemplo n.º 26
0
 def test_normalize_multi_dir(self):
     sut = PythonDeclaration("import biipyc")
     result = sut.normalize(['testuser1/pyc/pythondynlibs/biipyc.py'])
     self.assertEquals(
         PythonDeclaration(
             "import testuser1.pyc.pythondynlibs.biipyc as biipyc"), result)
 def test_complex_normalize_with_alias(self):
     sut = PythonDeclaration("from myblock import Parser as Hell")
     result = sut.normalize(['testuser/block/__init__.py', 'testuser/block/myblock.py'])
     self.assertEquals(PythonDeclaration("from testuser.block.myblock import Parser as Hell"),
                       result)
Ejemplo n.º 28
0
 def test_match_system_inexistent(self):
     sut = PythonDeclaration("import reee")
     validator = self.generate_python_sys_libs()
     self.assertEquals(set([]), sut.match_system(validator))
 def test_normalize_composed_import(self):
     sut = PythonDeclaration("import     biicode.common.edition.parsing")
     result = sut.normalize(['biicode/common/edition/parsing.py'])
     self.assertEquals(PythonDeclaration("import biicode.common.edition.parsing"), result)
Ejemplo n.º 30
0
 def explicit_declarations(self):
     result = set()
     result |= (set([PythonDeclaration(x.name) for x in self.imports]))
     result |= (set([CPPDeclaration(x) for x in self.c_includes]))
     result |= (set([DataDeclaration(x.name) for x in self.references]))
     return result
Ejemplo n.º 31
0
 def test_from_import_error(self):
     sut = PythonDeclaration("from biicode.common.edition impor Parser")
     self.assertIsNone(sut.block())