Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
d9b34bae
Unverified
Commit
d9b34bae
authored
Jun 25, 2024
by
Michael Goin
Committed by
GitHub
Jun 25, 2024
Browse files
[CI/Build] Add unit testing for FlexibleArgumentParser (#5798)
parent
c18ebfdd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
1 deletion
+60
-1
tests/test_utils.py
tests/test_utils.py
+60
-1
No files found.
tests/test_utils.py
View file @
d9b34bae
...
@@ -7,7 +7,8 @@ from typing import (TYPE_CHECKING, Any, AsyncIterator, Awaitable, Protocol,
...
@@ -7,7 +7,8 @@ from typing import (TYPE_CHECKING, Any, AsyncIterator, Awaitable, Protocol,
import
pytest
import
pytest
from
vllm.utils
import
deprecate_kwargs
,
get_open_port
,
merge_async_iterators
from
vllm.utils
import
(
FlexibleArgumentParser
,
deprecate_kwargs
,
get_open_port
,
merge_async_iterators
)
from
.utils
import
error_on_warning
from
.utils
import
error_on_warning
...
@@ -130,3 +131,61 @@ def test_get_open_port():
...
@@ -130,3 +131,61 @@ def test_get_open_port():
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s3
:
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s3
:
s3
.
bind
((
"localhost"
,
get_open_port
()))
s3
.
bind
((
"localhost"
,
get_open_port
()))
os
.
environ
.
pop
(
"VLLM_PORT"
)
os
.
environ
.
pop
(
"VLLM_PORT"
)
# Tests for FlexibleArgumentParser
@
pytest
.
fixture
def
parser
():
parser
=
FlexibleArgumentParser
()
parser
.
add_argument
(
'--image-input-type'
,
choices
=
[
'pixel_values'
,
'image_features'
])
parser
.
add_argument
(
'--model-name'
)
parser
.
add_argument
(
'--batch-size'
,
type
=
int
)
parser
.
add_argument
(
'--enable-feature'
,
action
=
'store_true'
)
return
parser
def
test_underscore_to_dash
(
parser
):
args
=
parser
.
parse_args
([
'--image_input_type'
,
'pixel_values'
])
assert
args
.
image_input_type
==
'pixel_values'
def
test_mixed_usage
(
parser
):
args
=
parser
.
parse_args
([
'--image_input_type'
,
'image_features'
,
'--model-name'
,
'facebook/opt-125m'
])
assert
args
.
image_input_type
==
'image_features'
assert
args
.
model_name
==
'facebook/opt-125m'
def
test_with_equals_sign
(
parser
):
args
=
parser
.
parse_args
(
[
'--image_input_type=pixel_values'
,
'--model-name=facebook/opt-125m'
])
assert
args
.
image_input_type
==
'pixel_values'
assert
args
.
model_name
==
'facebook/opt-125m'
def
test_with_int_value
(
parser
):
args
=
parser
.
parse_args
([
'--batch_size'
,
'32'
])
assert
args
.
batch_size
==
32
args
=
parser
.
parse_args
([
'--batch-size'
,
'32'
])
assert
args
.
batch_size
==
32
def
test_with_bool_flag
(
parser
):
args
=
parser
.
parse_args
([
'--enable_feature'
])
assert
args
.
enable_feature
is
True
args
=
parser
.
parse_args
([
'--enable-feature'
])
assert
args
.
enable_feature
is
True
def
test_invalid_choice
(
parser
):
with
pytest
.
raises
(
SystemExit
):
parser
.
parse_args
([
'--image_input_type'
,
'invalid_choice'
])
def
test_missing_required_argument
(
parser
):
parser
.
add_argument
(
'--required-arg'
,
required
=
True
)
with
pytest
.
raises
(
SystemExit
):
parser
.
parse_args
([])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment