示例#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
    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)

                    sut.copytree('', destination_path)

                    with sut.open(join(destination_path, 'basket',
                                       'apples')) as f:
                        self.assertEquals('apples', f.read())
                    with sut.open(join(destination_path, 'basket',
                                       'oranges')) as f:
                        self.assertEquals('oranges', f.read())
                    with sut.open(join(destination_path, 'basket',
                                       'bananas')) as f:
                        self.assertEquals('bananas', f.read())
示例#4
0
    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)

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

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

                    with self.assertRaises(FileNotFoundError):
                        sut.copy2('mangos', destination_path)
示例#5
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())
示例#6
0
    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())