예제 #1
0
파일: blok.py 프로젝트: petrus-v/AnyBlok
    def get_needed_blok(cls, blok):
        """Get and import/load the blok given with dependencies

        :param blok:
        :return:
        """
        if cls.has(blok):
            return True

        if blok not in cls.bloks:
            return False

        cls.get_needed_blok_dependencies(blok)
        cls.ordered_bloks.append(blok)
        EnvironmentManager.set('current_blok', blok)

        if not ImportManager.has(blok):
            # Import only if the blok doesn't exists, do not reload here
            mod = ImportManager.add(blok)
            mod.imports()
        else:
            mod = ImportManager.get(blok)
            mod.reload()

        if cls.bloks[blok].autoinstall:
            cls.auto_install.append(blok)

        return True
예제 #2
0
파일: blok.py 프로젝트: AnyBlok/AnyBlok
    def blok_importers(cls, blok):
        EnvironmentManager.set('current_blok', blok)

        if not ImportManager.has(blok):
            # Import only if the blok doesn't exists, do not reload here
            mod = ImportManager.add(blok)
            mod.imports()
        else:
            mod = ImportManager.get(blok)
            mod.reload()
예제 #3
0
 def test_imports(self):
     blok = ImportManager.add('mockblok')
     blok.imports()
     from .mockblok.mockpackage import mockfile1, mockfile2
     from .mockblok.mockpackage import submockpackage
     from .mockblok import mockfile
     assert mockfile1.foo == 'bar'
     assert mockfile2.foo == 'bar'
     assert submockpackage.mockfile1.foo == 'bar'
     assert submockpackage.mockfile2.foo == 'bar'
     assert mockfile.foo == 'bar'
예제 #4
0
파일: test_imp.py 프로젝트: AnyBlok/AnyBlok
 def test_imports(self):
     blok = ImportManager.add('mockblok')
     blok.imports()
     from .mockblok.mockpackage import mockfile1, mockfile2
     from .mockblok.mockpackage import submockpackage
     from .mockblok import mockfile
     self.assertEqual(mockfile1.foo, 'bar')
     self.assertEqual(mockfile2.foo, 'bar')
     self.assertEqual(submockpackage.mockfile1.foo, 'bar')
     self.assertEqual(submockpackage.mockfile2.foo, 'bar')
     self.assertEqual(mockfile.foo, 'bar')
예제 #5
0
 def test_imports(self):
     blok = ImportManager.add('mockblok')
     blok.imports()
     from .mockblok.mockpackage import mockfile1, mockfile2
     from .mockblok.mockpackage import submockpackage
     from .mockblok import mockfile
     self.assertEqual(mockfile1.foo, 'bar')
     self.assertEqual(mockfile2.foo, 'bar')
     self.assertEqual(submockpackage.mockfile1.foo, 'bar')
     self.assertEqual(submockpackage.mockfile2.foo, 'bar')
     self.assertEqual(mockfile.foo, 'bar')
예제 #6
0
파일: blok.py 프로젝트: jssuzanne/AnyBlok
    def get_need_blok(cls, blok):
        if cls.has(blok):
            return True

        if blok not in cls.bloks:
            return False

        cls.get_need_blok_linked_bloks(blok)
        cls.ordered_bloks.append(blok)
        EnvironmentManager.set('current_blok', blok)

        if not ImportManager.has(blok):
            # Import only if not exist don't reload here
            mod = ImportManager.add(blok)
            mod.imports()
        else:
            mod = ImportManager.get(blok)
            mod.reload()

        if cls.bloks[blok].autoinstall:
            cls.auto_install.append(blok)

        return True
예제 #7
0
    def get_need_blok(cls, blok):
        if cls.has(blok):
            return True

        if blok not in cls.bloks:
            return False

        cls.get_need_blok_linked_bloks(blok)
        cls.ordered_bloks.append(blok)
        EnvironmentManager.set('current_blok', blok)

        if not ImportManager.has(blok):
            # Import only if not exist don't reload here
            mod = ImportManager.add(blok)
            mod.imports()
        else:
            mod = ImportManager.get(blok)
            mod.reload()

        if cls.bloks[blok].autoinstall:
            cls.auto_install.append(blok)

        return True
예제 #8
0
    def test_reload(self):
        blok = ImportManager.add('mockblok')
        blok.imports()
        from .mockblok.mockpackage import mockfile1, mockfile2
        from .mockblok.mockpackage import submockpackage
        from .mockblok import mockfile

        with open(join(tests_path, 'mockpackage', 'mockfile1.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        with open(
                join(tests_path, 'mockpackage', 'submockpackage',
                     'mockfile2.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        with open(join(tests_path, 'mockfile.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        try:
            self.assertEqual(mockfile1.foo, 'bar')
            self.assertEqual(mockfile2.foo, 'bar')
            self.assertEqual(submockpackage.mockfile1.foo, 'bar')
            self.assertEqual(submockpackage.mockfile2.foo, 'bar')
            self.assertEqual(mockfile.foo, 'bar')
            blok.reload()
            self.assertEqual(mockfile1.foo, 'reload')
            self.assertEqual(mockfile2.foo, 'bar')
            self.assertEqual(submockpackage.mockfile1.foo, 'bar')
            self.assertEqual(submockpackage.mockfile2.foo, 'reload')
            self.assertEqual(mockfile.foo, 'reload')
        finally:
            with open(join(tests_path, 'mockfile.py'), 'w') as fp:
                fp.write(initial_file)

            with open(join(tests_path, 'mockpackage', 'mockfile1.py'),
                      'w') as fp:
                fp.write(initial_file)

            with open(
                    join(tests_path, 'mockpackage', 'submockpackage',
                         'mockfile2.py'), 'w') as fp:
                fp.write(initial_file)
예제 #9
0
파일: test_imp.py 프로젝트: AnyBlok/AnyBlok
    def test_reload(self):
        blok = ImportManager.add('mockblok')
        blok.imports()
        from .mockblok.mockpackage import mockfile1, mockfile2
        from .mockblok.mockpackage import submockpackage
        from .mockblok import mockfile

        with open(join(tests_path, 'mockpackage', 'mockfile1.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        with open(join(tests_path, 'mockpackage', 'submockpackage',
                       'mockfile2.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        with open(join(tests_path, 'mockfile.py'), 'w') as fp:
            fp.write("""foo = 'reload'""")

        try:
            self.assertEqual(mockfile1.foo, 'bar')
            self.assertEqual(mockfile2.foo, 'bar')
            self.assertEqual(submockpackage.mockfile1.foo, 'bar')
            self.assertEqual(submockpackage.mockfile2.foo, 'bar')
            self.assertEqual(mockfile.foo, 'bar')
            blok.reload()
            self.assertEqual(mockfile1.foo, 'reload')
            self.assertEqual(mockfile2.foo, 'bar')
            self.assertEqual(submockpackage.mockfile1.foo, 'bar')
            self.assertEqual(submockpackage.mockfile2.foo, 'reload')
            self.assertEqual(mockfile.foo, 'reload')
        finally:
            with open(join(tests_path, 'mockfile.py'), 'w') as fp:
                fp.write(initial_file)

            with open(join(tests_path, 'mockpackage',
                           'mockfile1.py'), 'w') as fp:
                fp.write(initial_file)

            with open(join(tests_path, 'mockpackage', 'submockpackage',
                           'mockfile2.py'), 'w') as fp:
                fp.write(initial_file)
예제 #10
0
 def test_get_unexisting_blok(self):
     try:
         ImportManager.get('mockblok2')
         self.fail('No watchdog for inexisting blok module')
     except ImportManagerException:
         pass
예제 #11
0
 def test_get_blok(self):
     ImportManager.add('mockblok')
     ImportManager.get('mockblok')
예제 #12
0
 def test_has_blok(self):
     ImportManager.add('mockblok')
     assert ImportManager.has('mockblok') is True
     assert ImportManager.has('mockblok2') is False
예제 #13
0
파일: test_imp.py 프로젝트: AnyBlok/AnyBlok
 def test_get_unexisting_blok(self):
     try:
         ImportManager.get('mockblok2')
         self.fail('No watchdog for inexisting blok module')
     except ImportManagerException:
         pass
예제 #14
0
파일: test_imp.py 프로젝트: AnyBlok/AnyBlok
 def test_get_blok(self):
     ImportManager.add('mockblok')
     ImportManager.get('mockblok')
예제 #15
0
파일: test_imp.py 프로젝트: AnyBlok/AnyBlok
 def test_has_blok(self):
     ImportManager.add('mockblok')
     self.assertEqual(ImportManager.has('mockblok'), True)
     self.assertEqual(ImportManager.has('mockblok2'), False)
예제 #16
0
 def test_has_blok(self):
     ImportManager.add('mockblok')
     self.assertEqual(ImportManager.has('mockblok'), True)
     self.assertEqual(ImportManager.has('mockblok2'), False)