Skip to content

Commit 856fcb4

Browse files
committed
♻️ split sample code test scripts
1 parent 1ec7301 commit 856fcb4

File tree

8 files changed

+74
-17
lines changed

8 files changed

+74
-17
lines changed

.github/workflows/_test-code-samples.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ on:
44
workflow_call:
55
workflow_dispatch:
66

7+
env:
8+
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
9+
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
10+
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
11+
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
12+
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
13+
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
14+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
15+
716
jobs:
817
test:
918
name: Run Code Samples
@@ -38,9 +47,13 @@ jobs:
3847
python -m pip install pip
3948
pip install -e .
4049
41-
- name: Tests code samples
50+
- name: Tests v2 sample code
51+
run: |
52+
./tests/test_v2_code_samples.sh
53+
54+
- name: Tests v1 sample code
4255
run: |
43-
./tests/test_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }} ${{ secrets.MINDEE_API_KEY_SE_TESTS }} ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }} ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
56+
./tests/test_v1_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}
4457
4558
- name: Notify Slack Action on Failure
4659
uses: ravsamhq/notify-slack-action@2.3.0

docs/extras/code_samples/v2_classification.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from mindee import (
77

88
input_path = "/path/to/the/file.ext"
99
api_key = "MY_API_KEY"
10-
model_id = "MY_CLASSIFICATION_MODEL_ID"
10+
model_id = "MY_MODEL_ID"
1111

1212
# Init a new client
1313
mindee_client = ClientV2(api_key)

docs/extras/code_samples/v2_crop.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from mindee import (
77

88
input_path = "/path/to/the/file.ext"
99
api_key = "MY_API_KEY"
10-
model_id = "MY_CROP_MODEL_ID"
10+
model_id = "MY_MODEL_ID"
1111

1212
# Init a new client
1313
mindee_client = ClientV2(api_key)

docs/extras/code_samples/v2_extraction.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ response = mindee_client.enqueue_and_get_result(
4242

4343
# Print a brief summary of the parsed data
4444
print(response.inference)
45+
46+
# Access the result fields
47+
fields: dict = response.inference.result.fields

docs/extras/code_samples/v2_ocr.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from mindee import (
77

88
input_path = "/path/to/the/file.ext"
99
api_key = "MY_API_KEY"
10-
model_id = "MY_OCR_MODEL_ID"
10+
model_id = "MY_MODEL_ID"
1111

1212
# Init a new client
1313
mindee_client = ClientV2(api_key)
@@ -31,5 +31,5 @@ response = mindee_client.enqueue_and_get_result(
3131
# Print a brief summary of the parsed data
3232
print(response.inference)
3333

34-
# Access the ocr result
34+
# Access the OCR result
3535
pages: list = response.inference.result.pages

docs/extras/code_samples/v2_split.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from mindee import (
77

88
input_path = "/path/to/the/file.ext"
99
api_key = "MY_API_KEY"
10-
model_id = "MY_SPLIT_MODEL_ID"
10+
model_id = "MY_MODEL_ID"
1111

1212
# Init a new client
1313
mindee_client = ClientV2(api_key)
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#! /bin/sh
22
set -e
33

4-
OUTPUT_FILE='./_test.py'
4+
OUTPUT_FILE='./_test_v1.py'
55
ACCOUNT=$1
66
ENDPOINT=$2
7-
API_KEY=$3
8-
API_KEY_V2=$4
9-
MODEL_ID=$5
10-
CLASSIFICATION_MODEL_ID=$6
11-
CROP_MODEL_ID=$7
12-
OCR_MODEL_ID=$8
13-
SPLIT_MODEL_ID=$9
147

15-
for f in $(find ./docs/extras/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" | sort -h)
8+
for f in $(
9+
find ./docs/extras/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" -not -name "v2_*.txt" | sort -h
10+
)
1611
do
1712
if echo "${f}" | grep -q "default_v2.txt"; then
1813
if [ -z "${API_KEY_V2}" ] || [ -z "${MODEL_ID}" ]; then
@@ -28,7 +23,7 @@ do
2823
echo "###############################################"
2924
echo
3025

31-
sed "s/my-api-key/${API_KEY}/" "${f}" > $OUTPUT_FILE
26+
sed "s/my-api-key/${MINDEE_API_KEY}/" "${f}" > $OUTPUT_FILE
3227
sed -i 's/\/path\/to\/the\/file.ext/.\/tests\/data\/file_types\/pdf\/blank_1.pdf/' $OUTPUT_FILE
3328

3429

tests/test_v2_code_samples.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /bin/sh
2+
set -e
3+
4+
OUTPUT_FILE='./_test_v2.py'
5+
6+
for f in $(
7+
find ./docs/extras/code_samples -maxdepth 1 -name "v2_*.txt" | sort -h
8+
)
9+
do
10+
echo
11+
echo "###############################################"
12+
echo "${f}"
13+
echo "###############################################"
14+
echo
15+
16+
sed "s/MY_API_KEY/${MINDEE_V2_API_KEY}/" "${f}" > $OUTPUT_FILE
17+
sed -i 's/\/path\/to\/the\/file.ext/.\/tests\/data\/file_types\/pdf\/blank_1.pdf/' $OUTPUT_FILE
18+
19+
if echo "${f}" | grep -q "v2_extraction.txt"
20+
then
21+
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID}/" $OUTPUT_FILE
22+
fi
23+
24+
if echo "${f}" | grep -q "v2_classification.txt"
25+
then
26+
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID}/" $OUTPUT_FILE
27+
fi
28+
29+
if echo "${f}" | grep -q "v2_crop.txt"
30+
then
31+
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CROP_MODEL_ID}/" $OUTPUT_FILE
32+
fi
33+
34+
if echo "${f}" | grep -q "v2_split.txt"
35+
then
36+
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID}/" $OUTPUT_FILE
37+
fi
38+
39+
if echo "${f}" | grep -q "v2_ocr.txt"
40+
then
41+
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_OCR_MODEL_ID}/" $OUTPUT_FILE
42+
fi
43+
44+
sleep 0.5 # avoid too many request errors
45+
python $OUTPUT_FILE
46+
done

0 commit comments

Comments
 (0)