from wex.url import URL

expected_lines = [
    b"FTP/1.0 200 OK\r\n",
    b"X-wex-url: ftp://anonymous:me@ftp.kernel.org/pub/site/README\r\n",
    b"\r\n",
    b"This directory contains files related to the operation of the\n",
]
expected_content = b''.join(expected_lines)

url = 'ftp://anonymous:me@ftp.kernel.org/pub/site/README'


def test_ftp_read():
    readables = list(URL(url).get())
    assert len(readables) == 1
    r0 = readables[0]
    chunk = r0.read(2**16)
    content = chunk
    chunk = r0.read(2**16)
    assert not chunk
    assert content.startswith(expected_content)


def test_ftp_readline():
    readables = list(URL(url).get())
    assert len(readables) == 1
    r0 = readables[0]
    first_four_lines = [r0.readline() for i in range(4)]
    assert first_four_lines == expected_lines[:4]

@@ -18,16 +18,72 @@
 rt URL%0A%0A
+url = 'ftp://anonymous:me@speedtest.tele2.net/1KB.zip'%0A%0A
 expected
@@ -141,253 +141,84 @@
 rl: 
-ftp://anonymous:me@ftp.kernel.org/pub/site/README%5Cr%5Cn%22,%0A    b%22%5Cr%5Cn%22,%0A    b%22This directory contains files related to the operation of the%5Cn%22,%0A%5D%0Aexpected_content = b''.join(expected_lines)%0A%0Aurl = 'ftp://anonymous:me@ftp.kernel.org/pub/site/README'
+%22 + url + %22%5Cr%5Cn%22,%0A    b%22%5Cr%5Cn%22,%0A%5D%0Aexpected_content = b''.join(expected_lines)
 %0A%0A%0Ad
@@ -557,32 +557,42 @@
 readables) == 1%0A
+    n = 3%0A
     r0 = readabl
@@ -600,35 +600,34 @@
 s%5B0%5D%0A    first_f
-our
+ew
 _lines = %5Br0.rea
@@ -649,17 +649,17 @@
 n range(
-4
+n
 )%5D%0A    a
@@ -675,11 +675,10 @@
 st_f
-our
+ew
 _lin
@@ -703,7 +703,7 @@
 es%5B:
-4
+n
 %5D%0A

Switch ftp server now ftp.kernel.org closed