Skip to content

Commit 99d1177

Browse files
iscai-msftiscai-msft
andauthored
[python] move unittests to this repo, add separate section for them (#6909)
Co-authored-by: iscai-msft <isabellavcai@gmail.com>
1 parent 45cad2d commit 99d1177

15 files changed

Lines changed: 493 additions & 17 deletions

packages/http-client-python/eng/scripts/ci/run-ci.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function myExecSync(command: string, flavor: string, name?: string): void {
5555
return;
5656
}
5757
execSync(getCommand(command, flavor, name), { stdio: "inherit" });
58+
execSync(getCommand(command, "unittests", name), { stdio: "inherit" });
5859
}
5960

6061
let venvPath = join(root, "venv");

packages/http-client-python/generator/test/generic_mock_api_tests/data/image.jpg renamed to packages/http-client-python/generator/test/data/image.jpg

File renamed without changes.

packages/http-client-python/generator/test/generic_mock_api_tests/data/image.png renamed to packages/http-client-python/generator/test/data/image.png

File renamed without changes.

packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_encode_bytes_async.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,6 @@ async def test_header(client: BytesClient):
9797
],
9898
)
9999

100-
101-
@pytest.fixture
102-
def png_data() -> bytes:
103-
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
104-
return file_in.read()
105-
106-
107100
@pytest.mark.asyncio
108101
async def test_request_body(client: BytesClient, png_data: bytes):
109102
await client.request_body.default(

packages/http-client-python/generator/test/generic_mock_api_tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import importlib
1111
from pathlib import Path
1212

13-
FILE_FOLDER = Path(__file__).parent
13+
DATA_FOLDER = Path(__file__).parent.parent
1414

1515

1616
def start_server_process():
@@ -65,11 +65,11 @@ def key_credential(core_library):
6565

6666
@pytest.fixture
6767
def png_data() -> bytes:
68-
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
68+
with open(str(DATA_FOLDER / "data/image.png"), "rb") as file_in:
6969
return file_in.read()
7070

7171

7272
@pytest.fixture
7373
def jpg_data() -> bytes:
74-
with open(str(FILE_FOLDER / "data/image.jpg"), "rb") as file_in:
74+
with open(str(DATA_FOLDER / "data/image.jpg"), "rb") as file_in:
7575
return file_in.read()

packages/http-client-python/generator/test/generic_mock_api_tests/test_encode_bytes.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,6 @@ def test_header(client: BytesClient):
9494
],
9595
)
9696

97-
98-
@pytest.fixture
99-
def png_data() -> bytes:
100-
with open(str(FILE_FOLDER / "data/image.png"), "rb") as file_in:
101-
return file_in.read()
102-
103-
10497
def test_request_body(client: BytesClient, png_data: bytes):
10598
client.request_body.default(
10699
value=png_data,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import importlib
7+
import pytest
8+
9+
@pytest.fixture
10+
def core_library():
11+
try:
12+
return importlib.import_module("azure.core")
13+
except ModuleNotFoundError:
14+
return importlib.import_module("corehttp")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-r ../dev_requirements.txt
2+
-e ../../../generator
3+
-e ../unbranded/generated/special-words
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
from enum import Enum, EnumMeta
7+
8+
9+
class _CaseInsensitiveEnumMeta(EnumMeta):
10+
def __getitem__(self, name):
11+
return super().__getitem__(name.upper())
12+
13+
def __getattr__(cls, name):
14+
"""Return the enum member matching `name`
15+
We use __getattr__ instead of descriptors or inserting into the enum
16+
class' __dict__ in order to support `name` and `value` being both
17+
properties for enum members (which live in the class' __dict__) and
18+
enum members themselves.
19+
"""
20+
try:
21+
return cls._member_map_[name.upper()]
22+
except KeyError:
23+
raise AttributeError(name)
24+
25+
26+
class EnumsWithCallableNames(str, Enum, metaclass=_CaseInsensitiveEnumMeta):
27+
"""Gets the unit of measurement."""
28+
29+
COUNT = "count"
30+
ENCODE = "encode"
31+
FIND = "find"
32+
JOIN = "join"
33+
34+
35+
def test_count():
36+
assert EnumsWithCallableNames.COUNT == "count"
37+
assert callable(EnumsWithCallableNames.count)
38+
39+
40+
def test_encode():
41+
assert EnumsWithCallableNames.ENCODE == "encode"
42+
assert callable(EnumsWithCallableNames.encode)
43+
44+
45+
def test_find():
46+
assert EnumsWithCallableNames.FIND == "find"
47+
assert callable(EnumsWithCallableNames.find)
48+
49+
50+
def test_join():
51+
assert EnumsWithCallableNames.JOIN == "join"
52+
assert callable(EnumsWithCallableNames.join)

packages/http-client-python/generator/test/generic_mock_api_tests/unittests/test_model_base_serialization.py renamed to packages/http-client-python/generator/test/unittests/test_model_base_serialization.py

File renamed without changes.

0 commit comments

Comments
 (0)