Skip to content

Commit a86de1c

Browse files
committed
use try finally block
1 parent eee3f48 commit a86de1c

File tree

2 files changed

+68
-62
lines changed

2 files changed

+68
-62
lines changed

tests/integration/synapseclient/models/async/test_json_schema_async.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,41 @@ def create_test_organization_with_schema(
7777
created_org = js.create_organization(org_name)
7878

7979
# Add a JSON schema
80-
schema = {
81-
"$schema": "http://json-schema.org/draft-07/schema#",
82-
"$id": "https://example.com/schema/productschema.json",
83-
"title": "Product Schema",
84-
"type": "object",
85-
"properties": {
86-
"productId": {
87-
"description": "The unique identifier for a product",
88-
"type": "integer",
89-
"const": 123,
90-
},
91-
"productName": {
92-
"description": "Name of the product",
93-
"type": "string",
94-
"const": "default product name",
95-
},
96-
"productDescription": {
97-
"description": "description of the product",
98-
"type": "string",
99-
},
100-
"productQuantity": {
101-
"description": "quantity of the product",
102-
"type": "integer",
80+
try:
81+
schema = {
82+
"$schema": "http://json-schema.org/draft-07/schema#",
83+
"$id": "https://example.com/schema/productschema.json",
84+
"title": "Product Schema",
85+
"type": "object",
86+
"properties": {
87+
"productId": {
88+
"description": "The unique identifier for a product",
89+
"type": "integer",
90+
"const": 123,
91+
},
92+
"productName": {
93+
"description": "Name of the product",
94+
"type": "string",
95+
"const": "default product name",
96+
},
97+
"productDescription": {
98+
"description": "description of the product",
99+
"type": "string",
100+
},
101+
"productQuantity": {
102+
"description": "quantity of the product",
103+
"type": "integer",
104+
},
103105
},
104-
},
105-
}
106-
test_org = js.JsonSchemaOrganization(org_name)
107-
created_schema = test_org.create_json_schema(schema, TEST_SCHEMA_NAME, "0.0.1")
108-
yield test_org, created_schema.uri
109-
110-
js.delete_json_schema(created_schema.uri)
111-
js.delete_organization(created_org["id"])
106+
}
107+
test_org = js.JsonSchemaOrganization(org_name)
108+
created_schema = test_org.create_json_schema(
109+
schema, TEST_SCHEMA_NAME, "0.0.1"
110+
)
111+
yield test_org, created_schema.uri
112+
finally:
113+
js.delete_json_schema(created_schema.uri)
114+
js.delete_organization(created_org["id"])
112115

113116
@pytest.fixture(scope="function")
114117
def file(self) -> File:

tests/integration/synapseclient/models/synchronous/test_json_schema.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,41 @@ def create_test_organization_with_schema(
7777
created_org = js.create_organization(org_name)
7878

7979
# Add a JSON schema
80-
schema = {
81-
"$schema": "http://json-schema.org/draft-07/schema#",
82-
"$id": "https://example.com/schema/productschema.json",
83-
"title": "Product Schema",
84-
"type": "object",
85-
"properties": {
86-
"productId": {
87-
"description": "The unique identifier for a product",
88-
"type": "integer",
89-
"const": 123,
90-
},
91-
"productName": {
92-
"description": "Name of the product",
93-
"type": "string",
94-
"const": "default product name",
95-
},
96-
"productDescription": {
97-
"description": "description of the product",
98-
"type": "string",
99-
},
100-
"productQuantity": {
101-
"description": "quantity of the product",
102-
"type": "integer",
80+
try:
81+
schema = {
82+
"$schema": "http://json-schema.org/draft-07/schema#",
83+
"$id": "https://example.com/schema/productschema.json",
84+
"title": "Product Schema",
85+
"type": "object",
86+
"properties": {
87+
"productId": {
88+
"description": "The unique identifier for a product",
89+
"type": "integer",
90+
"const": 123,
91+
},
92+
"productName": {
93+
"description": "Name of the product",
94+
"type": "string",
95+
"const": "default product name",
96+
},
97+
"productDescription": {
98+
"description": "description of the product",
99+
"type": "string",
100+
},
101+
"productQuantity": {
102+
"description": "quantity of the product",
103+
"type": "integer",
104+
},
103105
},
104-
},
105-
}
106-
test_org = js.JsonSchemaOrganization(org_name)
107-
created_schema = test_org.create_json_schema(schema, TEST_SCHEMA_NAME, "0.0.1")
108-
yield test_org, created_schema.uri
109-
110-
js.delete_json_schema(created_schema.uri)
111-
js.delete_organization(created_org["id"])
106+
}
107+
test_org = js.JsonSchemaOrganization(org_name)
108+
created_schema = test_org.create_json_schema(
109+
schema, TEST_SCHEMA_NAME, "0.0.1"
110+
)
111+
yield test_org, created_schema.uri
112+
finally:
113+
js.delete_json_schema(created_schema.uri)
114+
js.delete_organization(created_org["id"])
112115

113116
@pytest.fixture(scope="function")
114117
def file(self) -> File:

0 commit comments

Comments
 (0)