s3-testing 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Oliver Russell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.3
2
+ Name: s3-testing
3
+ Version: 0.0.1
4
+ Summary: S3 testing helpers
5
+ Author: Oliver Russell
6
+ Author-email: Oliver Russell <mrxoliver@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2023 Oliver Russell
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Requires-Dist: rclone-binaries
29
+ Requires-Python: >=3.12
30
+ Project-URL: homepage, https://github.com/leontrolski/s3-testing
31
+ Project-URL: documentation, https://github.com/leontrolski/s3-testing
32
+ Project-URL: repository, https://github.com/leontrolski/s3-testing.git
33
+ Description-Content-Type: text/markdown
34
+
35
+ # S3 testing
36
+
37
+ Simple S3 helper for testing with Python - no docker, brew, apt, etc - uses [rclone-binaries](https://github.com/leontrolski/rclone-binaries) (turns out [rclone has an S3 server baked in](https://rclone.org/commands/rclone_serve_s3/)). Pairs nicely with [postgresql-testing](https://github.com/leontrolski/postgresql-testing).
38
+
39
+ It's super dumb, just:
40
+
41
+ ```shell
42
+ pip install s3-testing
43
+ ```
44
+
45
+ ```python
46
+ import s3_testing
47
+
48
+ with s3_testing.serve() as config:
49
+ s3 = boto3.client(**config.as_boto_kwargs)
50
+
51
+ s3.create_bucket(Bucket="my-bucket")
52
+ s3.put_object(
53
+ Bucket="my-bucket",
54
+ Key="hello.txt",
55
+ Body=b"Hello from Python!",
56
+ )
57
+ ```
58
+
59
+ The default config puts all the data in `.s3-testing` - pop this in your `.gitignore`.
60
+
61
+ If you want a `pytest` fixture that gives you empty buckets, just [`shutil.rmtree(config.dir)`](test.py) between tests.
62
+
63
+ It has no auth, pass in whatever creds.
64
+
65
+ On my machine:
66
+
67
+ - Spinning up the server til it responds takes 700ms.
68
+ - Creating a bucket takes 1ms.
69
+ - Writing then reading a small object takes 3ms.
@@ -0,0 +1,35 @@
1
+ # S3 testing
2
+
3
+ Simple S3 helper for testing with Python - no docker, brew, apt, etc - uses [rclone-binaries](https://github.com/leontrolski/rclone-binaries) (turns out [rclone has an S3 server baked in](https://rclone.org/commands/rclone_serve_s3/)). Pairs nicely with [postgresql-testing](https://github.com/leontrolski/postgresql-testing).
4
+
5
+ It's super dumb, just:
6
+
7
+ ```shell
8
+ pip install s3-testing
9
+ ```
10
+
11
+ ```python
12
+ import s3_testing
13
+
14
+ with s3_testing.serve() as config:
15
+ s3 = boto3.client(**config.as_boto_kwargs)
16
+
17
+ s3.create_bucket(Bucket="my-bucket")
18
+ s3.put_object(
19
+ Bucket="my-bucket",
20
+ Key="hello.txt",
21
+ Body=b"Hello from Python!",
22
+ )
23
+ ```
24
+
25
+ The default config puts all the data in `.s3-testing` - pop this in your `.gitignore`.
26
+
27
+ If you want a `pytest` fixture that gives you empty buckets, just [`shutil.rmtree(config.dir)`](test.py) between tests.
28
+
29
+ It has no auth, pass in whatever creds.
30
+
31
+ On my machine:
32
+
33
+ - Spinning up the server til it responds takes 700ms.
34
+ - Creating a bucket takes 1ms.
35
+ - Writing then reading a small object takes 3ms.
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "s3-testing"
3
+ version = "0.0.1"
4
+ description = "S3 testing helpers"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = ["rclone-binaries"]
8
+
9
+ [[project.authors]]
10
+ name = "Oliver Russell"
11
+ email = "mrxoliver@gmail.com"
12
+
13
+ [project.license]
14
+ file = "LICENSE"
15
+
16
+ [project.urls]
17
+ homepage = "https://github.com/leontrolski/s3-testing"
18
+ documentation = "https://github.com/leontrolski/s3-testing"
19
+ repository = "https://github.com/leontrolski/s3-testing.git"
20
+
21
+ [build-system]
22
+ requires = ["uv_build>=0.9.17,<0.10.0"]
23
+ build-backend = "uv_build"
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "s3-testing"
3
+ version = "0.0.1"
4
+ description = "S3 testing helpers"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Oliver Russell", email = "mrxoliver@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.12"
10
+ license = { file = "LICENSE" }
11
+ dependencies = [
12
+ "rclone-binaries"
13
+ ]
14
+
15
+ [project.urls]
16
+ homepage = "https://github.com/leontrolski/s3-testing"
17
+ documentation = "https://github.com/leontrolski/s3-testing"
18
+ repository = "https://github.com/leontrolski/s3-testing.git"
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.9.17,<0.10.0"]
22
+ build-backend = "uv_build"
@@ -0,0 +1,69 @@
1
+ import shutil
2
+ import subprocess
3
+ from collections.abc import Iterator
4
+ from contextlib import contextmanager
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+ from typing import Literal, TypedDict
8
+
9
+ import rclone_binaries
10
+
11
+
12
+ class BotoKwargs(TypedDict):
13
+ service_name: str
14
+ endpoint_url: str
15
+ aws_access_key_id: str
16
+ aws_secret_access_key: str
17
+
18
+
19
+ @dataclass(frozen=True, kw_only=True)
20
+ class Config:
21
+ on_existing: Literal["use", "replace"] = "use"
22
+ dir: Path = Path(".s3-testing")
23
+ host: str = "localhost"
24
+ port: int = 9000
25
+
26
+ @property
27
+ def as_boto_kwargs(self) -> BotoKwargs:
28
+ return BotoKwargs(
29
+ service_name="s3",
30
+ endpoint_url=f"http://{self.host}:{self.port}",
31
+ aws_access_key_id="dummy",
32
+ aws_secret_access_key="dummy",
33
+ )
34
+
35
+
36
+ @contextmanager
37
+ def serve(c: Config = Config()) -> Iterator[Config]:
38
+ if c.on_existing == "replace":
39
+ shutil.rmtree(c.dir)
40
+ c.dir.mkdir(parents=True, exist_ok=True)
41
+ with (
42
+ open(c.dir / "stdout.log", "wb") as stdout_f,
43
+ open(c.dir / "stderr.log", "wb") as stderr_f,
44
+ ):
45
+ cmd = [
46
+ str(rclone_binaries.bin()),
47
+ "serve",
48
+ "s3",
49
+ *("--addr", f"{c.host}:{c.port}"),
50
+ # Make sure the FS matches the VFS
51
+ *("--dir-cache-time", "0"),
52
+ *("--poll-interval", "0"),
53
+ str(c.dir),
54
+ ]
55
+ process = subprocess.Popen(
56
+ cmd,
57
+ stdout=stdout_f,
58
+ stderr=stderr_f,
59
+ )
60
+ try:
61
+ yield c
62
+ finally:
63
+ # Shutdown
64
+ process.terminate()
65
+ try:
66
+ process.wait(timeout=1)
67
+ except subprocess.TimeoutExpired:
68
+ process.kill()
69
+ process.wait(timeout=5)
File without changes