-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancing Unit Testing by Adding sqldb Fixture #1270
Conversation
544b512
to
2e1c1b6
Compare
children = relationship( | ||
"Component", | ||
secondary=ParentChildAssociation.__table__, | ||
primaryjoin=id == ParentChildAssociation.parent_id, | ||
secondaryjoin=id == ParentChildAssociation.child_id, | ||
backref="children", | ||
backref="parents", | ||
cascade="all, delete", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got parents and children reversed
) | ||
.all() | ||
) | ||
return sum([c.parents for c in components], []) | ||
parents = [a.parent_id for a in assocations] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return unique_id, keep the same logic as MongoDBMetaDataStore
@@ -251,7 +255,7 @@ def _replace_object(self, info, identifier, type_id, version): | |||
Component.type_id == type_id, | |||
Component.identifier == identifier, | |||
Component.version == version, | |||
).update({'dict': info}) | |||
).update(info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix error structure
identifiers = [c.identifier for c in session.query(Component).all()] | ||
identifiers = sorted(set(identifiers), key=lambda x: identifiers.index(x)) | ||
return identifiers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deduplicate identifiers, keep the same logic with MongoDBMetaDataStore
0211178
to
0748303
Compare
6f52763
to
e8b91df
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1270 +/- ##
==========================================
- Coverage 80.33% 80.12% -0.22%
==========================================
Files 95 103 +8
Lines 6602 7341 +739
==========================================
+ Hits 5304 5882 +578
- Misses 1298 1459 +161 ☔ View full report in Codecov by Sentry. |
5b881d5
to
fa9a02d
Compare
args = Column(JSON) | ||
kwargs = Column(JSON) | ||
method_name = Column(String) | ||
method_name = Column(String(DEFAULT_LENGTH)) | ||
stdout = Column(JSON) | ||
stderr = Column(JSON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For databases such as MySQL, we need to supplement the size of this String. DEFAULT_LENGTH = 255
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
3aa4fe7
to
ee25d60
Compare
@pytest.mark.parametrize("db", [DBConfig.mongodb, DBConfig.sqldb], indirect=True) | ||
def test_only_uri(db): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test a use case using fixtures with MongoDB and SQL databases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
test/conftest.py
Outdated
def db(request, monkeypatch) -> Iterator[Datalayer]: | ||
# TODO: Use pre-defined config instead of dict here | ||
param = request.param if hasattr(request, 'param') else DBConfig.mongodb | ||
if isinstance(param, dict): | ||
# e.g. @pytest.mark.parametrize("db", [DBConfig.sqldb], indirect=True) | ||
setup_config = param.copy() | ||
elif isinstance(param, tuple): | ||
# e.g. @pytest.mark.parametrize("db", [(DBConfig.sqldb, {'n_data': 10})], indirect=True) # noqa: E501 | ||
setup_config = param[0].copy() | ||
setup_config.update(param[1] or {}) | ||
else: | ||
raise ValueError(f'Unsupported param type: {type(param)}') | ||
|
||
monkeypatch.setattr(CFG, 'data_backend', setup_config['data_backend']) | ||
|
||
db = create_db(CFG, **setup_config) | ||
yield db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Configure the db fixture in test cases using the predefined DBConfig.
Standardize fixture creation using configuration settings, with support for MongoDB and SQL databases.
Then, every test case can use the same fixture, yet they can still have different setup behaviors.
- DBConfig.mongodb_empty
- DBConfig.sqldb_empty
- DBConfig.mongodb (include: encoder, data, model, vector_index)
- DBConfig.sqldb (include: encoder, data, model, vector_index)
The above four are the most commonly used configurations. If there are more frequently used database preset configurations, new configurations can also be preset, as follows:
- DBConfig.mongodb_no_vector_index (include: encoder, data, model)
- DBConfig.sqldb_no_vector_index (include: encoder, data, model)
- DBConfig.mongodb_data (include: encoder, data)
- DBConfig.sqldb_data (include: encoder, data)
For example:
default setup behavior with using mongodb
def test_delete_many(db):
...
empty mongodb
@pytest.mark.parametrize("db", [DBConfig.mongodb_empty], indirect=True)
def test_execute_insert_and_find(db):
...
empty mongodb
and empty sqldb
@pytest.mark.parametrize(
"db", [DBConfig.mongodb_empty, DBConfig.sqldb_empty], indirect=True
)
def test_add_version(db):
....
do not add vector_index and add 500 data points
pytest.mark.parametrize(
"db",
[
(DBConfig.mongodb_no_vector_index, {'n_data': 500}),
(DBConfig.sqldb_no_vector_index, {'n_data': 500}),
],
indirect=True,
)
def test_dataset(db):
...
or use config param to do this
pytest.mark.parametrize(
"db",
[
(DBConfig.mongodb, {'add_vector_index': False, 'n_data': 500}),
(DBConfig.sqldb, {'add_vector_index': False, 'n_data': 500}),
],
indirect=True,
)
def test_dataset(db):
...
do not add vector_index and add default size (5) data points
pytest.mark.parametrize(
"db",
[
DBConfig.mongodb_no_vector_index,
DBConfig.sqldb_no_vector_index,
],
indirect=True,
)
def test_dataset(db):
...
This is an optimization I found while working, which involves combining the MongoDB and SQL DB fixtures. What do you think, should we do this? Or should we keep the fixtures separate? If we separate them, it might be a bit more troublesome to use different fixtures for a single test case.
WDYT? @thejumpman2323 @blythed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ee25d60
to
5a23976
Compare
5a23976
to
070193c
Compare
070193c
to
ee83876
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one comment and then we can merge.
ee83876
to
8d8a7de
Compare
8d8a7de
to
12c0d70
Compare
12c0d70
to
52617a4
Compare
Description
#673
Related Issues
Checklist
make test
successfully?Additional Notes or Comments