コード例 #1
0
    async def test_copytree(self):
        with TemporaryDirectory() as source_path_1:
            (Path(source_path_1) / 'basket').mkdir()
            with TemporaryDirectory() as source_path_2:
                (Path(source_path_2) / 'basket').mkdir()
                with open(Path(source_path_1) / 'basket' / 'apples', 'w') as f:
                    f.write('apples')
                with open(Path(source_path_2) / 'basket' / 'apples', 'w') as f:
                    f.write('notapples')
                with open(Path(source_path_1) / 'basket' / 'oranges', 'w') as f:
                    f.write('oranges')
                with open(Path(source_path_2) / 'basket' / 'bananas', 'w') as f:
                    f.write('bananas')

                with TemporaryDirectory() as destination_path:
                    sut = FileSystem((source_path_1, None), (source_path_2, None))

                    await sut.copytree('', destination_path)

                    async with sut.open(Path(destination_path) / 'basket' / 'apples') as f:
                        self.assertEquals('apples', await f.read())
                    async with sut.open(Path(destination_path) / 'basket' / 'oranges') as f:
                        self.assertEquals('oranges', await f.read())
                    async with sut.open(Path(destination_path) / 'basket' / 'bananas') as f:
                        self.assertEquals('bananas', await f.read())
コード例 #2
0
    async def test_copy2(self):
        with TemporaryDirectory() as source_path_1:
            with TemporaryDirectory() as source_path_2:
                with open(Path(source_path_1) / 'apples', 'w') as f:
                    f.write('apples')
                with open(Path(source_path_2) / 'apples', 'w') as f:
                    f.write('notapples')
                with open(Path(source_path_1) / 'oranges', 'w') as f:
                    f.write('oranges')
                with open(Path(source_path_2) / 'bananas', 'w') as f:
                    f.write('bananas')

                with TemporaryDirectory() as destination_path:
                    sut = FileSystem((source_path_1, None), (source_path_2, None))

                    await sut.copy2('apples', destination_path)
                    await sut.copy2('oranges', destination_path)
                    await sut.copy2('bananas', destination_path)

                    async with sut.open(Path(destination_path) / 'apples') as f:
                        self.assertEquals('apples', await f.read())
                    async with sut.open(Path(destination_path) / 'oranges') as f:
                        self.assertEquals('oranges', await f.read())
                    async with sut.open(Path(destination_path) / 'bananas') as f:
                        self.assertEquals('bananas', await f.read())

                    with self.assertRaises(FileNotFoundError):
                        await sut.copy2('mangos', destination_path)
コード例 #3
0
    async def test_open_with_second_file_path_alternative_first_source_path(self):
        with TemporaryDirectory() as source_path_1:
            with TemporaryDirectory() as source_path_2:
                with open(Path(source_path_1) / 'apples', 'w') as f:
                    f.write('apples')
                with open(Path(source_path_2) / 'apples', 'w') as f:
                    f.write('notapples')

                sut = FileSystem((source_path_1, None), (source_path_2, None))

                async with sut.open('pinkladies', 'apples') as f:
                    self.assertEquals('apples', await f.read())
コード例 #4
0
ファイル: test_fs.py プロジェクト: gholamiayub/betty
    def test_open_with_second_file_path_alternative_first_source_path(self):
        with TemporaryDirectory() as source_path_1:
            with TemporaryDirectory() as source_path_2:
                with open(join(source_path_1, 'apples'), 'w') as f:
                    f.write('apples')
                with open(join(source_path_2, 'apples'), 'w') as f:
                    f.write('notapples')

                sut = FileSystem(source_path_1, source_path_2)

                with sut.open('pinkladies', 'apples') as f:
                    self.assertEquals('apples', f.read())
コード例 #5
0
ファイル: test_fs.py プロジェクト: rohithjayaraman/betty
    async def test_copytree(self):
        with TemporaryDirectory() as source_path_1:
            os.makedirs(join(source_path_1, 'basket'))
            with TemporaryDirectory() as source_path_2:
                os.makedirs(join(source_path_2, 'basket'))
                with open(join(source_path_1, 'basket', 'apples'), 'w') as f:
                    f.write('apples')
                with open(join(source_path_2, 'basket', 'apples'), 'w') as f:
                    f.write('notapples')
                with open(join(source_path_1, 'basket', 'oranges'), 'w') as f:
                    f.write('oranges')
                with open(join(source_path_2, 'basket', 'bananas'), 'w') as f:
                    f.write('bananas')

                with TemporaryDirectory() as destination_path:
                    sut = FileSystem(source_path_1, source_path_2)

                    await sut.copytree('', destination_path)

                    with await sut.open(
                            join(destination_path, 'basket', 'apples')) as f:
                        self.assertEquals('apples', f.read())
                    with await sut.open(
                            join(destination_path, 'basket', 'oranges')) as f:
                        self.assertEquals('oranges', f.read())
                    with await sut.open(
                            join(destination_path, 'basket', 'bananas')) as f:
                        self.assertEquals('bananas', f.read())
コード例 #6
0
ファイル: test_fs.py プロジェクト: rohithjayaraman/betty
    async def test_copy2(self):
        with TemporaryDirectory() as source_path_1:
            with TemporaryDirectory() as source_path_2:
                with open(join(source_path_1, 'apples'), 'w') as f:
                    f.write('apples')
                with open(join(source_path_2, 'apples'), 'w') as f:
                    f.write('notapples')
                with open(join(source_path_1, 'oranges'), 'w') as f:
                    f.write('oranges')
                with open(join(source_path_2, 'bananas'), 'w') as f:
                    f.write('bananas')

                with TemporaryDirectory() as destination_path:
                    sut = FileSystem(source_path_1, source_path_2)

                    await sut.copy2('apples', destination_path)
                    await sut.copy2('oranges', destination_path)
                    await sut.copy2('bananas', destination_path)

                    with await sut.open(join(destination_path, 'apples')) as f:
                        self.assertEquals('apples', f.read())
                    with await sut.open(join(destination_path,
                                             'oranges')) as f:
                        self.assertEquals('oranges', f.read())
                    with await sut.open(join(destination_path,
                                             'bananas')) as f:
                        self.assertEquals('bananas', f.read())

                    with self.assertRaises(FileNotFoundError):
                        await sut.copy2('mangos', destination_path)
コード例 #7
0
 def __init__(self, configuration: Configuration):
     self._ancestry = Ancestry()
     self._configuration = configuration
     self._resources = FileSystem(
         join(dirname(abspath(__file__)), 'resources'))
     self._event_dispatcher = EventDispatcher()
     self._plugins = {}
     self._init_plugins()
     if configuration.resources_directory_path:
         self._resources.paths.appendleft(
             configuration.resources_directory_path)
コード例 #8
0
 def __init__(self, configuration: Configuration):
     self._ancestry = Ancestry()
     self._configuration = configuration
     self._resources = FileSystem(
         join(dirname(abspath(__file__)), 'resources'))
     self._event_dispatcher = EventDispatcher()
     self._translations = defaultdict(gettext.NullTranslations)
     self._plugins = OrderedDict()
     self._init_plugins()
     self._init_event_listeners()
     self._init_resources()
     self._init_translations()
コード例 #9
0
ファイル: app.py プロジェクト: bartfeenstra/betty
 def __init__(self, configuration: Configuration):
     self._active = False
     self._ancestry = Ancestry()
     self._configuration = configuration
     self._assets = FileSystem()
     self._dispatcher = None
     self._localized_url_generator = AppUrlGenerator(configuration)
     self._static_url_generator = StaticPathUrlGenerator(configuration)
     self._debug = None
     self._locale = None
     self._translations = defaultdict(gettext.NullTranslations)
     self._default_translations = None
     self._extensions = None
     self._activation_exit_stack = AsyncExitStack()
     self._jinja2_environment = None
     self._renderer = None
     self._executor = None
     self._locks = Locks()
     self._http_client = None
コード例 #10
0
ファイル: site.py プロジェクト: patlx/betty
 def __init__(self, configuration: Configuration):
     self._site_stack = []
     self._ancestry = Ancestry()
     self._configuration = configuration
     self._assets = FileSystem(join(dirname(abspath(__file__)), 'assets'))
     self._dispatcher = Dispatcher()
     self._localized_url_generator = SiteUrlGenerator(configuration)
     self._static_url_generator = StaticPathUrlGenerator(configuration)
     self._locale = None
     self._translations = defaultdict(gettext.NullTranslations)
     self._default_translations = None
     self._plugins = OrderedDict()
     self._plugin_exit_stack = AsyncExitStack()
     self._init_plugins()
     self._init_dispatch_handlers()
     self._init_assets()
     self._init_translations()
     self._jinja2_environment = None
     self._renderer = None
     self._executor = None
     self._locks = Locks()
コード例 #11
0
ファイル: test_fs.py プロジェクト: ricardokirkner/betty
    async def test_open(self):
        with TemporaryDirectory() as source_path_1:
            with TemporaryDirectory() as source_path_2:
                with open(path.join(source_path_1, 'apples'), 'w') as f:
                    f.write('apples')
                with open(path.join(source_path_2, 'apples'), 'w') as f:
                    f.write('notapples')
                with open(path.join(source_path_1, 'oranges'), 'w') as f:
                    f.write('oranges')
                with open(path.join(source_path_2, 'bananas'), 'w') as f:
                    f.write('bananas')

                sut = FileSystem(source_path_1, source_path_2)

                with await sut.open('apples') as f:
                    self.assertEquals('apples', f.read())
                with await sut.open('oranges') as f:
                    self.assertEquals('oranges', f.read())
                with await sut.open('bananas') as f:
                    self.assertEquals('bananas', f.read())

                with self.assertRaises(FileNotFoundError):
                    with await sut.open('mangos'):
                        pass