@@ -20,11 +20,21 @@ def sftp_session(ssh_client_session):
20
20
del sftp_sess # noqa: WPS420
21
21
22
22
23
- @pytest .fixture
24
- def transmit_payload ():
25
- """Generate a binary test payload."""
26
- uuid_name = uuid .uuid4 ()
27
- return 'Hello, {name!s}' .format (name = uuid_name ).encode ()
23
+ @pytest .fixture (
24
+ params = (32 , 1024 + 1 ),
25
+ ids = ('small-payload' , 'large-payload' ),
26
+ )
27
+ def transmit_payload (request : pytest .FixtureRequest ):
28
+ """Generate binary test payloads of assorted sizes.
29
+
30
+ The choice 32 is arbitrary small value.
31
+
32
+ The choice 1024 + 1 is meant to be 1B larger than the chunk size used in
33
+ sftp.pyx to make sure we excercise at least two rounds of reading/writing.
34
+ """
35
+ payload_len = request .param
36
+ random_bytes = [ord (random .choice (string .printable )) for _ in range (payload_len )] # NOSONAR
37
+ return bytes (random_bytes )
28
38
29
39
30
40
@pytest .fixture
@@ -93,35 +103,3 @@ def test_put_existing(dst_exists_path, src_path, sftp_session, transmit_payload)
93
103
"""Check that SFTP file upload works when target file exists."""
94
104
sftp_session .put (str (src_path ), str (dst_exists_path ))
95
105
assert dst_exists_path .read_bytes () == transmit_payload
96
-
97
-
98
- @pytest .fixture
99
- def large_payload ():
100
- """Generate a large 1025 byte (1024 + 1B) test payload."""
101
- payload_len = 1024 + 1
102
- random_bytes = [ord (random .choice (string .printable )) for _ in range (payload_len )]
103
- return bytes (random_bytes )
104
-
105
-
106
- @pytest .fixture
107
- def src_path_large (tmp_path , large_payload ):
108
- """Return a remote path to a 1025 byte-sized file.
109
-
110
- The pylibssh chunk size is 1024 so the test needs a file that would
111
- execute at least two loops.
112
- """
113
- path = tmp_path / 'large.txt'
114
- path .write_bytes (large_payload )
115
- return path
116
-
117
-
118
- def test_put_large (dst_path , src_path_large , sftp_session , large_payload ):
119
- """Check that SFTP can upload large file."""
120
- sftp_session .put (str (src_path_large ), str (dst_path ))
121
- assert dst_path .read_bytes () == large_payload
122
-
123
-
124
- def test_get_large (dst_path , src_path_large , sftp_session , large_payload ):
125
- """Check that SFTP can download large file."""
126
- sftp_session .get (str (src_path_large ), str (dst_path ))
127
- assert dst_path .read_bytes () == large_payload
0 commit comments