Example #1
0
    def test_when_exception(self):
        """ ブロック内で例外が発生しても一時ディレクトリが削除される """
        with pytest.raises(Exception):
            with tempdir() as dirpath:
                raise Exception('Oops!')

        assert not os.path.exists(dirpath)
Example #2
0
    def test_delete_files(self):
        """ 一時ディレクトリ内にファイルがあってもディレクトリごと削除される """
        with tempdir() as dirpath:
            filepath = os.path.join(dirpath, 'temporary.txt')
            with open(filepath, 'wb') as f:
                f.write(b'Hello, World!')

        assert not os.path.exists(dirpath)
def cmd(tool_opts, open_browser, tool, source):
    with tempdir() as dirpath:
        server = Server()
        source_abspath = os.path.abspath(source)
        command_instance = get_command(tool, source_abspath, dirpath,
                                       tool_opts)
        command_str = str(command_instance)
        sh = shell(command_str, cwd=dirpath)
        sh()
        server.watch(source, sh)

        image_filepath = command_instance.destination
        image_filename = os.path.basename(image_filepath)

        page = render(image_filename)
        deploy(dirpath, page)

        server.serve(root=dirpath, open_url_delay=open_browser)
Example #4
0
    def test(self):
        """ 使い終わった一時ディレクトリが削除される """
        with tempdir() as dirpath:
            assert type(dirpath) == str

        assert not os.path.exists(dirpath)