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

Correctly loading the methods from relatively imported classes #364

Conversation

kunalvishwasrao
Copy link
Contributor

@kunalvishwasrao kunalvishwasrao commented Jul 2, 2024

After merging #360 all the previous issues were fixed but when I created step implementations inside a class and tried use those steps inside specs, I was getting an error with positional arguments missing.

This issue arises because the update_step_resgistry_with_class() method inside the impl_loader.py file is unable to fetch all the methods inside that step implementation file inside get_all_methods_in() method due to the file_path being a relative file path.

Resolving the relative file path into an absolute file path inside update_step_resgistry_with_class() method #365

Hey @BugDiver, @zabil, can you please help me merge this PR to resolve this issue.
Apologies for this follow-up PR, missed this update in the previous PR.

Thanks!😄

getgauge/impl_loader.py Outdated Show resolved Hide resolved
@zabil
Copy link
Member

zabil commented Jul 3, 2024

I'll take a look at this. Thanks for raising #360 will use the info to test it locally.

@kunalvishwasrao
Copy link
Contributor Author

I'll take a look at this. Thanks for raising #360 will use the info to test it locally.

Sure, thanks a lot @zabil😄

@chadlwilson
Copy link
Contributor

It seems pretty clear to me that this code needs automated tests or this is going to be broken again at some point. Is there any reason it can't be tested?

@kunalvishwasrao kunalvishwasrao force-pushed the feature/correctly-load-impl-methods-from-classes branch from eeef098 to 4161583 Compare July 3, 2024 13:46
dependabot bot and others added 6 commits July 3, 2024 19:26
Bumps the pip-dependencies group with 2 updates: [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools).

Updates `importlib-metadata` from 7.1.0 to 7.2.1
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v7.1.0...v7.2.1)

Updates `setuptools` from 70.0.0 to 70.1.0
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v70.0.0...v70.1.0)

---
updated-dependencies:
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: pip-dependencies
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: pip-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
…tgauge#362)

Bumps the pip-dependencies group with 3 updates in the / directory: [debugpy](https://github.com/microsoft/debugpy), [importlib-metadata](https://github.com/python/importlib_metadata) and [setuptools](https://github.com/pypa/setuptools).

Updates `debugpy` from 1.8.1 to 1.8.2
- [Release notes](https://github.com/microsoft/debugpy/releases)
- [Commits](microsoft/debugpy@v1.8.1...v1.8.2)

Updates `importlib-metadata` from 7.2.1 to 8.0.0
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](python/importlib_metadata@v7.2.1...v8.0.0)

Updates `setuptools` from 70.1.0 to 70.1.1
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v70.1.0...v70.1.1)

---
updated-dependencies:
- dependency-name: debugpy
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pip-dependencies
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: pip-dependencies
- dependency-name: setuptools
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: pip-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: BugDiver <vinayshankar00@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
…on to getgauge#360)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Correctly loading the methods from relatively imported classes (getgauge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>

Co-authored-by: Zabil Cheriya Maliackal <zabil@users.noreply.github.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
@kunalvishwasrao kunalvishwasrao force-pushed the feature/correctly-load-impl-methods-from-classes branch from f6ef53b to bf770bf Compare July 3, 2024 13:56
@zabil
Copy link
Member

zabil commented Jul 3, 2024

Yeah I agree. I am having a tough time testing it locally at the moment because the install scripts are not working as expected and there are some python version issues.

@kunalvishwasrao is there a way you can look into some unit tests for this logic?

@kunalvishwasrao
Copy link
Contributor Author

Yeah sure @zabil I'll look into unit tests for testing this logic.
Thanks 😄

…gauge#365)

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
@kunalvishwasrao
Copy link
Contributor Author

Hey @zabil,

I've added a unittest file to test the update_step_resgistry_with_class() method for relative imports of methods inside a class as well as outside as suggested. Can you please review it and let me know if its fine.

Thanks!😄

getgauge/impl_loader.py Show resolved Hide resolved
os.chdir('tests')
method_list = update_step_resgistry_with_class(Sample(), self.relative_file_path)
os.chdir(curr_dir)
self.assertEqual(2, len(method_list))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
self.assertEqual(2, len(method_list))
self.assertEqual(["Greet <name> from inside the class",
"Greet <name> from outside the class"],
[method.step_text for method in method_list])```
Will be good to make this assertion specific

def test_update_step_resgistry_with_class(self):
curr_dir = os.getcwd()
os.chdir('tests')
method_list = update_step_resgistry_with_class(Sample(), self.relative_file_path)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
method_list = update_step_resgistry_with_class(Sample(), self.relative_file_path)
method_list = update_step_registry_with_class(Sample(), self.relative_file_path)

I understand this is not related to you change but will be a good time to fix the typo in the test and the implementation, if that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure sure, will do it 😄

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
@kunalvishwasrao
Copy link
Contributor Author

Hey @zabil,

Updated the method name and unttests as suggested. Can you please let me know if it looks fine.

Thank!😄

@gaugebot
Copy link

gaugebot bot commented Jul 5, 2024

@kunalvishwasrao Thank you for contributing to gauge-python. Your pull request has been labeled as a release candidate 🎉🎉.

Merging this PR will trigger a release.

Please bump up the version as part of this PR.

Instructions to bump the version can found at CONTRIBUTING.md

If the CONTRIBUTING.md file does not exist or does not include instructions about bumping up the version, please looks previous commits in git history to see what changes need to be done.

Signed-off-by: Kunal Vishwasrao <kunal.vishwasrao@gmail.com>
@kunalvishwasrao
Copy link
Contributor Author

Hey @zabil,

Thanks for the review and approval!😄

@zabil zabil enabled auto-merge (squash) July 6, 2024 20:30
@zabil zabil merged commit 76450d7 into getgauge:master Jul 6, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants