Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
3ba1fb70
Unverified
Commit
3ba1fb70
authored
1 year ago
by
Siraj R Aizlewood
Browse files
Options
Downloads
Patches
Plain Diff
New PyTest
test_from_file_invalid_config()
parent
4ed7bf9d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/test_layer.py
+25
-3
25 additions, 3 deletions
tests/unit/test_layer.py
with
25 additions
and
3 deletions
tests/unit/test_layer.py
+
25
−
3
View file @
3ba1fb70
...
...
@@ -351,6 +351,30 @@ class TestRouteLayer:
LayerConfig
.
from_file
(
str
(
config_path
))
assert
"
Unsupported file type
"
in
str
(
excinfo
.
value
)
def
test_from_file_invalid_config
(
self
,
tmp_path
):
# Define an invalid configuration JSON
invalid_config_json
=
"""
{
"
encoder_type
"
:
"
cohere
"
,
"
encoder_name
"
:
"
embed-english-v3.0
"
,
"
routes
"
:
"
This should be a list, not a string
"
}
"""
# Write the invalid configuration to a temporary JSON file
config_path
=
tmp_path
/
"
invalid_config.json
"
with
open
(
config_path
,
"
w
"
)
as
file
:
file
.
write
(
invalid_config_json
)
# Patch the is_valid function to return False for this test
with
patch
(
"
semantic_router.layer.is_valid
"
,
return_value
=
False
):
# Attempt to load the LayerConfig from the temporary file
# and assert that it raises an exception due to invalid configuration
with
pytest
.
raises
(
Exception
)
as
excinfo
:
LayerConfig
.
from_file
(
str
(
config_path
))
assert
"
Invalid config JSON or YAML
"
in
str
(
excinfo
.
value
),
"
Loading an invalid configuration should raise an exception.
"
def
test_from_file_with_llm
(
self
,
tmp_path
):
llm_config_json
=
"""
{
...
...
@@ -376,9 +400,7 @@ class TestRouteLayer:
# Load the LayerConfig from the temporary file
layer_config
=
LayerConfig
.
from_file
(
str
(
config_path
))
# Assertions to verify the behavior
# Since we're not mocking importlib.import_module, we skip the assertion
# that checks if the module was imported. Instead, we focus on the result.
# Using BaseLLM because trying to create a useable Mock LLM is a nightmare.
assert
isinstance
(
layer_config
.
routes
[
0
].
llm
,
BaseLLM
),
"
LLM should be instantiated and associated with the route based on the config
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment