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
7e4fe6d5
Unverified
Commit
7e4fe6d5
authored
1 year ago
by
James Briggs
Browse files
Options
Downloads
Patches
Plain Diff
add env var to other tests
parent
d16f5891
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/unit/test_layer.py
+10
-9
10 additions, 9 deletions
tests/unit/test_layer.py
with
10 additions
and
9 deletions
tests/unit/test_layer.py
+
10
−
9
View file @
7e4fe6d5
import
os
import
pytest
from
unittest.mock
import
Mock
,
mock_open
,
patch
from
unittest.mock
import
mock_open
,
patch
from
semantic_router.encoders
import
BaseEncoder
,
CohereEncoder
,
OpenAIEncoder
from
semantic_router.layer
import
LayerConfig
,
RouteLayer
...
...
@@ -186,6 +186,7 @@ class TestRouteLayer:
os
.
remove
(
"
test_output.json
"
)
def
test_yaml
(
self
,
openai_encoder
,
routes
):
os
.
environ
[
"
OPENAI_API_KEY
"
]
=
"
test_api_key
"
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes
)
route_layer
.
to_yaml
(
"
test_output.yaml
"
)
assert
os
.
path
.
exists
(
"
test_output.yaml
"
)
...
...
@@ -197,18 +198,18 @@ class TestRouteLayer:
os
.
remove
(
"
test_output.yaml
"
)
def
test_config
(
self
,
openai_encoder
,
routes
):
os
.
environ
[
"
OPENAI_API_KEY
"
]
=
"
test_api_key
"
route_layer
=
RouteLayer
(
encoder
=
openai_encoder
,
routes
=
routes
)
# confirm route creation functions as expected
layer_config
=
route_layer
.
to_config
()
assert
layer_config
.
routes
==
routes
with
patch
(
"
semantic_router.encoders.OpenAIEncoder
"
,
new_callable
=
Mock
):
# now load from config and confirm it's the same
route_layer_from_config
=
RouteLayer
.
from_config
(
layer_config
)
assert
(
route_layer_from_config
.
index
==
route_layer
.
index
).
all
()
assert
(
route_layer_from_config
.
categories
==
route_layer
.
categories
).
all
()
assert
(
route_layer_from_config
.
score_threshold
==
route_layer
.
score_threshold
)
# now load from config and confirm it's the same
route_layer_from_config
=
RouteLayer
.
from_config
(
layer_config
)
assert
(
route_layer_from_config
.
index
==
route_layer
.
index
).
all
()
assert
(
route_layer_from_config
.
categories
==
route_layer
.
categories
).
all
()
assert
(
route_layer_from_config
.
score_threshold
==
route_layer
.
score_threshold
)
# Add more tests for edge cases and error handling as needed.
...
...
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