Пример #1
0
def test_file_name_519():
    """Test open_file with a PEP 519 file name"""
    data = 'abc'
    with make_file(data) as file_name:
        fobj = open_file(File519(file_name), encoding='utf-8')
        assert fobj.read() == data
        fobj.close()
Пример #2
0
def test_file_name_path():
    """Test open_file with a pathlib file name"""
    data = 'abc'
    with make_file(data) as file_name:
        fobj = open_file(pathlib.Path(file_name), encoding='utf-8')
        assert fobj.read() == data
        fobj.close()
Пример #3
0
def test_file_name_bin():
    """Test open_file with a bytes file name"""
    data = 'abc'
    with make_file(data) as file_name:
        fobj = open_file(file_name.encode('utf-8'), encoding='utf-8')
        assert fobj.read() == data
        fobj.close()
Пример #4
0
def test_file_name_str():
    """Test open_file with a string file name"""
    data = 'abc'
    with make_file(data) as file_name:
        fobj = open_file(file_name, encoding='utf-8')
        assert fobj.read() == data
        fobj.close()
Пример #5
0
def test_file_name_descriptor():
    """Test open_file with a file descriptor"""
    data = 'abc'
    with make_file(data) as file_name, open(file_name) as bobj:
        fobj = open_file(bobj.fileno(), encoding='utf-8', closefd=False)
        assert fobj.read() == data
        fobj.close()
        assert bobj.closed is False
Пример #6
0
def test_file_name_obj():
    """Test open_file with a file object"""
    data = 'abc'
    with make_file(data) as file_name, open(file_name) as bobj:
        with pytest.raises(TypeError):
            open_file(bobj)