toml-combine 0.1.7__tar.gz → 0.2.0__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.
Files changed (23) hide show
  1. {toml_combine-0.1.7 → toml_combine-0.2.0}/.github/workflows/ci.yml +2 -2
  2. {toml_combine-0.1.7 → toml_combine-0.2.0}/.pre-commit-config.yaml +2 -2
  3. {toml_combine-0.1.7 → toml_combine-0.2.0}/PKG-INFO +118 -59
  4. {toml_combine-0.1.7 → toml_combine-0.2.0}/README.md +116 -57
  5. {toml_combine-0.1.7 → toml_combine-0.2.0}/pyproject.toml +1 -1
  6. {toml_combine-0.1.7 → toml_combine-0.2.0}/tests/test.toml +3 -59
  7. toml_combine-0.2.0/tests/test_cli.py +58 -0
  8. {toml_combine-0.1.7 → toml_combine-0.2.0}/tests/test_combiner.py +60 -109
  9. toml_combine-0.2.0/tests/test_lib.py +115 -0
  10. toml_combine-0.2.0/toml_combine/__init__.py +5 -0
  11. {toml_combine-0.1.7 → toml_combine-0.2.0}/toml_combine/cli.py +29 -11
  12. {toml_combine-0.1.7 → toml_combine-0.2.0}/toml_combine/combiner.py +42 -105
  13. {toml_combine-0.1.7 → toml_combine-0.2.0}/toml_combine/exceptions.py +4 -0
  14. toml_combine-0.1.7/toml_combine/__init__.py → toml_combine-0.2.0/toml_combine/lib.py +12 -9
  15. toml_combine-0.2.0/toml_combine/toml.py +27 -0
  16. {toml_combine-0.1.7 → toml_combine-0.2.0}/uv.lock +11 -2
  17. toml_combine-0.1.7/tests/test_cli.py +0 -15
  18. toml_combine-0.1.7/tests/test_lib.py +0 -65
  19. toml_combine-0.1.7/toml_combine/toml.py +0 -17
  20. {toml_combine-0.1.7 → toml_combine-0.2.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  21. {toml_combine-0.1.7 → toml_combine-0.2.0}/.github/renovate.json5 +0 -0
  22. {toml_combine-0.1.7 → toml_combine-0.2.0}/tests/result.json +0 -0
  23. {toml_combine-0.1.7 → toml_combine-0.2.0}/toml_combine/__main__.py +0 -0
@@ -29,7 +29,7 @@ jobs:
29
29
  - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
30
30
 
31
31
  - name: Install the latest version of uv
32
- uses: astral-sh/setup-uv@f94ec6bedd8674c4426838e6b50417d36b6ab231 # v5
32
+ uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5
33
33
  with:
34
34
  python-version: ${{ matrix.python-version }}
35
35
 
@@ -53,7 +53,7 @@ jobs:
53
53
  ref: ${{ github.ref }}
54
54
 
55
55
  - name: Install the latest version of uv
56
- uses: astral-sh/setup-uv@f94ec6bedd8674c4426838e6b50417d36b6ab231 # v5
56
+ uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5
57
57
 
58
58
  - name: Build wheel & sdist
59
59
  run: uv build
@@ -22,11 +22,11 @@ repos:
22
22
  - id: mixed-line-ending
23
23
  - repo: https://github.com/astral-sh/uv-pre-commit
24
24
  # uv version.
25
- rev: 0.6.12
25
+ rev: 0.6.13
26
26
  hooks:
27
27
  - id: uv-lock
28
28
  - repo: https://github.com/astral-sh/ruff-pre-commit
29
- rev: v0.11.0
29
+ rev: v0.11.4
30
30
  hooks:
31
31
  - id: ruff
32
32
  args: [--fix, --unsafe-fixes, --show-fixes]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toml-combine
3
- Version: 0.1.7
3
+ Version: 0.2.0
4
4
  Summary: A tool for combining complex configurations in TOML format.
5
5
  Author-email: Joachim Jablon <ewjoachim@gmail.com>
6
6
  License-Expression: MIT
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
16
  Requires-Python: >=3.9
17
- Requires-Dist: tomli>=2.2.1
17
+ Requires-Dist: tomlkit
18
18
  Description-Content-Type: text/markdown
19
19
 
20
20
  # Toml-combine
@@ -35,12 +35,6 @@ The configuration file is usually a TOML file. Here's a small example:
35
35
  [dimensions]
36
36
  environment = ["production", "staging"]
37
37
 
38
- [[output]]
39
- environment = "production"
40
-
41
- [[output]]
42
- environment = "staging"
43
-
44
38
  [default]
45
39
  name = "my-service"
46
40
  registry = "gcr.io/my-project/"
@@ -61,16 +55,6 @@ Dimensions lets you describe the main "thing" that makes the outputs differents,
61
55
  service might be `frontend` or `backend`. Some combinations of dimensions might not
62
56
  exists, for example, maybe there's no `staging` in `eu`.
63
57
 
64
- ### Outputs
65
-
66
- Create a `output` for each configuration you want to generate, and specify the
67
- dimensions relevant for this output. It's ok to omit some dimensions when they're not
68
- used for a given output.
69
-
70
- > [!Note]
71
- > Defining a list as the value of one or more dimensions in a output
72
- > is a shorthand for defining all combinations of dimensions
73
-
74
58
  ### Default
75
59
 
76
60
  The common configuration to start from, before we start overlaying overrides on top.
@@ -93,7 +77,7 @@ specific to more specific, each one overriding the values of the previous ones:
93
77
 
94
78
  ### The configuration itself
95
79
 
96
- Under the layer of `dimensions/output/default/override` system, what you actually define
80
+ Under the layer of `dimensions/default/override/mapping` system, what you actually define
97
81
  in the configuration is completely up to you. That said, only nested
98
82
  "dictionnaries"/"objects"/"tables"/"mapping" (those are all the same things in
99
83
  Python/JS/Toml lingo) will be merged between the default and the overrides, while
@@ -110,9 +94,6 @@ Let's look at an example:
110
94
  [dimensions]
111
95
  environment = ["production", "staging"]
112
96
 
113
- [[output]]
114
- environment = ["production", "staging"]
115
-
116
97
  [default]
117
98
  fruits = [{name="apple", color="red"}]
118
99
 
@@ -121,17 +102,16 @@ when.environment = "staging"
121
102
  fruits = [{name="orange", color="orange"}]
122
103
  ```
123
104
 
124
- In this example, on staging, `fruits` is `[{name="orange", color="orange"}]` and not `[{name="apple", color="red"}, {name="orange", color="orange"}]`.
125
- The only way to get multiple values to be merged is if they are tables: you'll need
105
+ In this example, with `{"environment": "staging"}`, `fruits` is
106
+ `[{name="orange", color="orange"}]` and not
107
+ `[{name="apple", color="red"}, {name="orange", color="orange"}]`.
108
+ The only way to get multiple values to be merged is if they are dicts: you'll need
126
109
  to chose an element to become the key:
127
110
 
128
111
  ```toml
129
112
  [dimensions]
130
113
  environment = ["production", "staging"]
131
114
 
132
- [[output]]
133
- environment = ["production", "staging"]
134
-
135
115
  [default]
136
116
  fruits.apple.color = "red"
137
117
 
@@ -146,22 +126,54 @@ This example is simple because `name` is a natural choice for the key. In some c
146
126
  the choice is less natural, but you can always decide to name the elements of your
147
127
  list and use that name as a key. Also, yes, you'll loose ordering.
148
128
 
149
- ### A bigger example
129
+ ### Mapping
130
+
131
+ When you call the tool either with the CLI or the lib (see both below), you will have to
132
+ provide a mapping of the desired dimentions. These values will be compared to overrides
133
+ to apply overrides when relevant. It's ok to omit some dimensions, corresponding
134
+ overrides won't be selected. The mapping you pass is also returned in the output as a
135
+ dict under the `dimensions` key.
136
+
137
+ By default, the output is `toml` though you can switch to `json` with `--format=json`
138
+
139
+ ## CLI
140
+
141
+ Example with the config from the previous section:
142
+
143
+ ```console
144
+ $ toml-combine path/to/config.toml --environment=staging
145
+ [dimensions]
146
+ environment = "staging"
147
+
148
+ [fruits]
149
+ apple.color = "red"
150
+ orange.color = "orange"
151
+ ```
152
+
153
+ ## Lib
154
+
155
+ ```python
156
+ import toml_combine
157
+
158
+
159
+ result = toml_combine.combine(config_file=config_file, environment="staging")
160
+
161
+ print(result)
162
+ {
163
+ "dimensions": {"environment": "staging"},
164
+ "fruits": {"apple": {"color": "red"}, "orange": {"color": "orange"}}
165
+ }
166
+ ```
167
+
168
+ You can pass either `config` (TOML string or dict) or `config_file` (`pathlib.Path` or string path) to `combine()`. All other `kwargs` specify the mapping you want.
169
+
170
+ ## A bigger example
150
171
 
151
172
  ```toml
152
173
  [dimensions]
153
174
  environment = ["production", "staging", "dev"]
154
175
  service = ["frontend", "backend"]
155
176
 
156
- # All 4 combinations of those values will exist
157
- [[output]]
158
- environment = ["production", "staging"]
159
- service = ["frontend", "backend"]
160
-
161
- # On dev, the "service" is not defined. That's ok.
162
- [[output]]
163
- environment = "dev"
164
-
165
177
  [default]
166
178
  registry = "gcr.io/my-project/"
167
179
  service_account = "my-service-account"
@@ -181,39 +193,86 @@ container.port = 8080
181
193
  name = "service-dev"
182
194
  when.environment = "dev"
183
195
  container.env.DEBUG = true
196
+
197
+ [[override]]
198
+ when.environment = ["staging", "dev"]
199
+ when.service = "backend"
200
+ container.env.ENABLE_EXPENSIVE_MONITORING = false
184
201
  ```
185
202
 
186
- ### CLI
203
+ This produces the following configs:
187
204
 
188
205
  ```console
189
- $ toml-combine {path/to/config.toml}
206
+ $ uv run toml-combine example.toml --environment=production --service=frontend
207
+ registry = "gcr.io/my-project/"
208
+ service_account = "my-service-account"
209
+ name = "service-frontend"
210
+ [dimensions]
211
+ environment = "production"
212
+ service = "frontend"
213
+
214
+ [container]
215
+ image_name = "my-image-frontend"
190
216
  ```
191
217
 
192
- Generates all the outputs described by the given TOML config.
218
+ ```console
219
+ $ toml-combine example.toml --environment=production --service=backend
220
+ registry = "gcr.io/my-project/"
221
+ service_account = "my-service-account"
222
+ name = "service-backend"
223
+ [dimensions]
224
+ environment = "production"
225
+ service = "backend"
193
226
 
194
- Note that you can restrict generation to some dimension values by passing
195
- `--{dimension}={value}`
227
+ [container]
228
+ image_name = "my-image-backend"
229
+ port = 8080
230
+ ```
196
231
 
197
- ## Lib
232
+ ```console
233
+ $ toml-combine example.toml --environment=staging --service=frontend
234
+ registry = "gcr.io/my-project/"
235
+ service_account = "my-service-account"
236
+ name = "service-frontend"
237
+ [dimensions]
238
+ environment = "staging"
239
+ service = "frontend"
198
240
 
199
- ```python
200
- import toml_combine
241
+ [container]
242
+ image_name = "my-image-frontend"
243
+ ```
201
244
 
245
+ ```console
246
+ $ toml-combine example.toml --environment=staging --service=backend
247
+ registry = "gcr.io/my-project/"
248
+ service_account = "my-service-account"
249
+ name = "service-backend"
250
+ [dimensions]
251
+ environment = "staging"
252
+ service = "backend"
202
253
 
203
- result = toml_combine.combine(
204
- config_file=config_file,
205
- environment=["production", "staging"],
206
- type="job",
207
- job=["manage", "special-command"],
208
- )
254
+ [container]
255
+ image_name = "my-image-backend"
256
+ port = 8080
209
257
 
210
- print(result)
211
- {
212
- "production-job-manage": {...},
213
- "production-job-special-command": {...},
214
- "staging-job-manage": {...},
215
- "staging-job-special-command": {...},
216
- }
258
+ [container.env]
259
+ ENABLE_EXPENSIVE_MONITORING = false
217
260
  ```
218
261
 
219
- You can pass either `config` (TOML string or dict) or `config_file` (`pathlib.Path` or string path) to `combine()`. Additional `kwargs` restrict the output.
262
+ ```console
263
+ $ toml-combine example.toml --environment=dev --service=backend
264
+ registry = "gcr.io/my-project/"
265
+ service_account = "my-service-account"
266
+ name = "service-backend"
267
+ [dimensions]
268
+ environment = "dev"
269
+ service = "backend"
270
+
271
+ [container]
272
+ image_name = "my-image-backend"
273
+ port = 8080
274
+ [container.env]
275
+ DEBUG = true
276
+ ENABLE_EXPENSIVE_MONITORING = false
277
+
278
+ ```
@@ -16,12 +16,6 @@ The configuration file is usually a TOML file. Here's a small example:
16
16
  [dimensions]
17
17
  environment = ["production", "staging"]
18
18
 
19
- [[output]]
20
- environment = "production"
21
-
22
- [[output]]
23
- environment = "staging"
24
-
25
19
  [default]
26
20
  name = "my-service"
27
21
  registry = "gcr.io/my-project/"
@@ -42,16 +36,6 @@ Dimensions lets you describe the main "thing" that makes the outputs differents,
42
36
  service might be `frontend` or `backend`. Some combinations of dimensions might not
43
37
  exists, for example, maybe there's no `staging` in `eu`.
44
38
 
45
- ### Outputs
46
-
47
- Create a `output` for each configuration you want to generate, and specify the
48
- dimensions relevant for this output. It's ok to omit some dimensions when they're not
49
- used for a given output.
50
-
51
- > [!Note]
52
- > Defining a list as the value of one or more dimensions in a output
53
- > is a shorthand for defining all combinations of dimensions
54
-
55
39
  ### Default
56
40
 
57
41
  The common configuration to start from, before we start overlaying overrides on top.
@@ -74,7 +58,7 @@ specific to more specific, each one overriding the values of the previous ones:
74
58
 
75
59
  ### The configuration itself
76
60
 
77
- Under the layer of `dimensions/output/default/override` system, what you actually define
61
+ Under the layer of `dimensions/default/override/mapping` system, what you actually define
78
62
  in the configuration is completely up to you. That said, only nested
79
63
  "dictionnaries"/"objects"/"tables"/"mapping" (those are all the same things in
80
64
  Python/JS/Toml lingo) will be merged between the default and the overrides, while
@@ -91,9 +75,6 @@ Let's look at an example:
91
75
  [dimensions]
92
76
  environment = ["production", "staging"]
93
77
 
94
- [[output]]
95
- environment = ["production", "staging"]
96
-
97
78
  [default]
98
79
  fruits = [{name="apple", color="red"}]
99
80
 
@@ -102,17 +83,16 @@ when.environment = "staging"
102
83
  fruits = [{name="orange", color="orange"}]
103
84
  ```
104
85
 
105
- In this example, on staging, `fruits` is `[{name="orange", color="orange"}]` and not `[{name="apple", color="red"}, {name="orange", color="orange"}]`.
106
- The only way to get multiple values to be merged is if they are tables: you'll need
86
+ In this example, with `{"environment": "staging"}`, `fruits` is
87
+ `[{name="orange", color="orange"}]` and not
88
+ `[{name="apple", color="red"}, {name="orange", color="orange"}]`.
89
+ The only way to get multiple values to be merged is if they are dicts: you'll need
107
90
  to chose an element to become the key:
108
91
 
109
92
  ```toml
110
93
  [dimensions]
111
94
  environment = ["production", "staging"]
112
95
 
113
- [[output]]
114
- environment = ["production", "staging"]
115
-
116
96
  [default]
117
97
  fruits.apple.color = "red"
118
98
 
@@ -127,22 +107,54 @@ This example is simple because `name` is a natural choice for the key. In some c
127
107
  the choice is less natural, but you can always decide to name the elements of your
128
108
  list and use that name as a key. Also, yes, you'll loose ordering.
129
109
 
130
- ### A bigger example
110
+ ### Mapping
111
+
112
+ When you call the tool either with the CLI or the lib (see both below), you will have to
113
+ provide a mapping of the desired dimentions. These values will be compared to overrides
114
+ to apply overrides when relevant. It's ok to omit some dimensions, corresponding
115
+ overrides won't be selected. The mapping you pass is also returned in the output as a
116
+ dict under the `dimensions` key.
117
+
118
+ By default, the output is `toml` though you can switch to `json` with `--format=json`
119
+
120
+ ## CLI
121
+
122
+ Example with the config from the previous section:
123
+
124
+ ```console
125
+ $ toml-combine path/to/config.toml --environment=staging
126
+ [dimensions]
127
+ environment = "staging"
128
+
129
+ [fruits]
130
+ apple.color = "red"
131
+ orange.color = "orange"
132
+ ```
133
+
134
+ ## Lib
135
+
136
+ ```python
137
+ import toml_combine
138
+
139
+
140
+ result = toml_combine.combine(config_file=config_file, environment="staging")
141
+
142
+ print(result)
143
+ {
144
+ "dimensions": {"environment": "staging"},
145
+ "fruits": {"apple": {"color": "red"}, "orange": {"color": "orange"}}
146
+ }
147
+ ```
148
+
149
+ You can pass either `config` (TOML string or dict) or `config_file` (`pathlib.Path` or string path) to `combine()`. All other `kwargs` specify the mapping you want.
150
+
151
+ ## A bigger example
131
152
 
132
153
  ```toml
133
154
  [dimensions]
134
155
  environment = ["production", "staging", "dev"]
135
156
  service = ["frontend", "backend"]
136
157
 
137
- # All 4 combinations of those values will exist
138
- [[output]]
139
- environment = ["production", "staging"]
140
- service = ["frontend", "backend"]
141
-
142
- # On dev, the "service" is not defined. That's ok.
143
- [[output]]
144
- environment = "dev"
145
-
146
158
  [default]
147
159
  registry = "gcr.io/my-project/"
148
160
  service_account = "my-service-account"
@@ -162,39 +174,86 @@ container.port = 8080
162
174
  name = "service-dev"
163
175
  when.environment = "dev"
164
176
  container.env.DEBUG = true
177
+
178
+ [[override]]
179
+ when.environment = ["staging", "dev"]
180
+ when.service = "backend"
181
+ container.env.ENABLE_EXPENSIVE_MONITORING = false
165
182
  ```
166
183
 
167
- ### CLI
184
+ This produces the following configs:
168
185
 
169
186
  ```console
170
- $ toml-combine {path/to/config.toml}
187
+ $ uv run toml-combine example.toml --environment=production --service=frontend
188
+ registry = "gcr.io/my-project/"
189
+ service_account = "my-service-account"
190
+ name = "service-frontend"
191
+ [dimensions]
192
+ environment = "production"
193
+ service = "frontend"
194
+
195
+ [container]
196
+ image_name = "my-image-frontend"
171
197
  ```
172
198
 
173
- Generates all the outputs described by the given TOML config.
199
+ ```console
200
+ $ toml-combine example.toml --environment=production --service=backend
201
+ registry = "gcr.io/my-project/"
202
+ service_account = "my-service-account"
203
+ name = "service-backend"
204
+ [dimensions]
205
+ environment = "production"
206
+ service = "backend"
174
207
 
175
- Note that you can restrict generation to some dimension values by passing
176
- `--{dimension}={value}`
208
+ [container]
209
+ image_name = "my-image-backend"
210
+ port = 8080
211
+ ```
177
212
 
178
- ## Lib
213
+ ```console
214
+ $ toml-combine example.toml --environment=staging --service=frontend
215
+ registry = "gcr.io/my-project/"
216
+ service_account = "my-service-account"
217
+ name = "service-frontend"
218
+ [dimensions]
219
+ environment = "staging"
220
+ service = "frontend"
179
221
 
180
- ```python
181
- import toml_combine
222
+ [container]
223
+ image_name = "my-image-frontend"
224
+ ```
182
225
 
226
+ ```console
227
+ $ toml-combine example.toml --environment=staging --service=backend
228
+ registry = "gcr.io/my-project/"
229
+ service_account = "my-service-account"
230
+ name = "service-backend"
231
+ [dimensions]
232
+ environment = "staging"
233
+ service = "backend"
183
234
 
184
- result = toml_combine.combine(
185
- config_file=config_file,
186
- environment=["production", "staging"],
187
- type="job",
188
- job=["manage", "special-command"],
189
- )
235
+ [container]
236
+ image_name = "my-image-backend"
237
+ port = 8080
190
238
 
191
- print(result)
192
- {
193
- "production-job-manage": {...},
194
- "production-job-special-command": {...},
195
- "staging-job-manage": {...},
196
- "staging-job-special-command": {...},
197
- }
239
+ [container.env]
240
+ ENABLE_EXPENSIVE_MONITORING = false
198
241
  ```
199
242
 
200
- You can pass either `config` (TOML string or dict) or `config_file` (`pathlib.Path` or string path) to `combine()`. Additional `kwargs` restrict the output.
243
+ ```console
244
+ $ toml-combine example.toml --environment=dev --service=backend
245
+ registry = "gcr.io/my-project/"
246
+ service_account = "my-service-account"
247
+ name = "service-backend"
248
+ [dimensions]
249
+ environment = "dev"
250
+ service = "backend"
251
+
252
+ [container]
253
+ image_name = "my-image-backend"
254
+ port = 8080
255
+ [container.env]
256
+ DEBUG = true
257
+ ENABLE_EXPENSIVE_MONITORING = false
258
+
259
+ ```
@@ -34,7 +34,7 @@ classifiers = [
34
34
  "Programming Language :: Python :: 3.13",
35
35
  ]
36
36
 
37
- dependencies = ["tomli>=2.2.1"]
37
+ dependencies = ["tomlkit"]
38
38
 
39
39
  [tool.uv]
40
40
  default-groups = ["test"]
@@ -5,64 +5,6 @@ stack = ["next", "django"]
5
5
  service = ["api", "admin"]
6
6
  job = ["manage", "special-command"]
7
7
 
8
- [[output]]
9
- environment = "staging"
10
- stack = "next"
11
- type = "service"
12
-
13
- [[output]]
14
- environment = "staging"
15
- stack = "django"
16
- type = "service"
17
- service = "api"
18
-
19
- [[output]]
20
- environment = "staging"
21
- stack = "django"
22
- type = "service"
23
- service = "admin"
24
-
25
- [[output]]
26
- environment = "staging"
27
- stack = "django"
28
- type = "job"
29
- job = "manage"
30
-
31
- [[output]]
32
- environment = "staging"
33
- stack = "django"
34
- type = "job"
35
- job = "special-command"
36
-
37
- [[output]]
38
- environment = "production"
39
- stack = "next"
40
- type = "service"
41
-
42
- [[output]]
43
- environment = "production"
44
- stack = "django"
45
- type = "service"
46
- service = "api"
47
-
48
- [[output]]
49
- environment = "production"
50
- stack = "django"
51
- type = "service"
52
- service = "admin"
53
-
54
- [[output]]
55
- environment = "production"
56
- stack = "django"
57
- type = "job"
58
- job = "manage"
59
-
60
- [[output]]
61
- environment = "production"
62
- stack = "django"
63
- type = "job"
64
- job = "special-command"
65
-
66
8
  [default]
67
9
  registry.region = "us"
68
10
 
@@ -107,7 +49,9 @@ cloudsql_instance = "staging-postgres"
107
49
  containers.app.env.APP_FOO = "qux"
108
50
 
109
51
  [[override]]
110
- when.service = "admin"
52
+ # The following line defines when in an array. It's not useful, as there's only one
53
+ # value, but we want to test that arrays work too.
54
+ when.service = ["admin"]
111
55
  containers.app.name = "admin"
112
56
  containers.app.env.APP_ADMIN_ENABLED = true
113
57
  containers.app.env.APP_ID = 1234
@@ -0,0 +1,58 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import pathlib
5
+
6
+ from toml_combine import cli, toml
7
+
8
+
9
+ def test_cli__json(capsys):
10
+ """Test the CLI."""
11
+ cli.cli(
12
+ argv=[
13
+ "tests/test.toml",
14
+ "--format",
15
+ "json",
16
+ "--environment",
17
+ "staging",
18
+ "--type",
19
+ "service",
20
+ "--stack",
21
+ "django",
22
+ "--service",
23
+ "admin",
24
+ ]
25
+ )
26
+ out, err = capsys.readouterr()
27
+ print("out:")
28
+ print(out)
29
+ print("err:")
30
+ print(err)
31
+
32
+ expected = json.loads((pathlib.Path(__file__).parent / "result.json").read_text())
33
+ assert json.loads(out) == expected["staging-service-django-admin"]
34
+
35
+
36
+ def test_cli__toml(capsys):
37
+ """Test the CLI."""
38
+ cli.cli(
39
+ argv=[
40
+ "tests/test.toml",
41
+ "--environment",
42
+ "staging",
43
+ "--type",
44
+ "service",
45
+ "--stack",
46
+ "django",
47
+ "--service",
48
+ "admin",
49
+ ]
50
+ )
51
+ out, err = capsys.readouterr()
52
+ print("out:")
53
+ print(out)
54
+ print("err:")
55
+ print(err)
56
+
57
+ expected = json.loads((pathlib.Path(__file__).parent / "result.json").read_text())
58
+ assert toml.loads(out) == expected["staging-service-django-admin"]