Skip to content
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

Update tests #618

Merged
merged 4 commits into from
Aug 13, 2024
Merged

Update tests #618

merged 4 commits into from
Aug 13, 2024

Conversation

stevemessick
Copy link
Contributor

This exercises all the API functions, unlike the original, which only run a few. It might be best to use View File to see python_api_tests.py. (I didn't even look at the diff.)

@stevemessick stevemessick requested review from rosbo and jplotts August 7, 2024 21:39
tests/python_api_tests.py Outdated Show resolved Hide resolved
@stevemessick stevemessick requested a review from rosbo August 7, 2024 22:27
tests/python_api_tests.py Outdated Show resolved Hide resolved
tests/python_api_tests.py Outdated Show resolved Hide resolved
@stevemessick stevemessick changed the title Update test script [WIP] Update test script Aug 8, 2024
@stevemessick stevemessick changed the title [WIP] Update test script Update tests Aug 13, 2024
@stevemessick stevemessick requested a review from jplotts August 13, 2024 16:04
Copy link
Contributor

@jplotts jplotts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock, with some optional comments. This is a definitely great improvement over the current lack of testing, but it would be nice to iterate in the future on decoupling the tests and maybe adding a few more validations.

from kaggle import api


# Unit test names include a letter to sort them in run order.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[no action required] - It looks like test order is important because some tests depend on previous tests? Ideally each test would be independent, but I don't think it's easy to disentangle this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for example, you need to create a dataset before you can update or download it. We could make tests that ran each function required, and that might be easier to maintain. But they would also run much more slowly. For now, I'll keep the dependencies.

Comment on lines 49 to 54
def tearDownModule():
file = os.path.join(dataset_directory, api.DATASET_METADATA_FILE)
if os.path.exists(file):
os.remove(file)
if os.path.exists(api.DATASET_METADATA_FILE):
os.remove(api.DATASET_METADATA_FILE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two files cleaned up globally vs as part of the test where they are created? It looks like other files are cleaned up per-test, so maybe this one should be too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are required to run other tests. It turned out that I wasn't deleting some other metadata files, so I added them here.

version_num = 0
except FileNotFoundError:
version_num = 0
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed.

json.dump(meta_data, f, indent=2)
return meta_data

def create_dataset_metadata_file(dataset_dir):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - I don't think this really creates anything. IIUC, it just reads an existing file and returns the version number or 0 if the file doesn't exist? Does it need a different name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to initialize_dataset_metadata_file().

# KAGGLE_KEY=local_api_token
# KAGGLE_USERNAME=<kaggle-user-name>

model_owner = api.config_values['username']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - I think this is used in the kernel tests as well, so maybe should be called something like test_user?

self.test_dataset_b_metadata()
try:
api.dataset_metadata_update(self.dataset, None)
# TODO Make the API method return something, and not exit when it fails.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to download the dataset metadata and make sure it was updated? At least it would be some sort of validation...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API doesn't have a function to download dataset metadata.

print(new_dataset.error) # This is likely to happen, and that's OK.
except ApiException as e:
self.fail(f"dataset_create_new failed: {e}")
# finally:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this cleanup is commented out?

try:
ms = api.models_list()
self.assertIsInstance(ms['models'], list)
# self.assertGreater(ms['models'], 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there not any models? It seems like this check should be uncommented.

try:
model = api.model_create_new('model')
if model.hasError:
# Handle potential errors gracefully (potentially skip the test)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this self.fail?

except ApiException as e:
self.fail(f"model_instance_create failed: {e}")

def test_model_instance_b_wait_after_create(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK temporarily, but it might be nice to leave a TODO for something better. I think the intention is to run this if b and c are running, but not if just b or c runs? One option could be to refactor the shared setup and include the time.sleep there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a TODO.

@stevemessick stevemessick merged commit d2534a2 into main Aug 13, 2024
4 checks passed
@stevemessick stevemessick deleted the update-tests branch August 13, 2024 22:37
@jplotts jplotts mentioned this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants