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

Dynamically generate invalid config files in unit tests #220

Merged
merged 12 commits into from
Dec 1, 2023

Conversation

aadityasinha-dotcom
Copy link
Contributor

What It Does

Dynamically generate invalid config files in unit tests

How to Test

Review Checklist
I certify that I have:

Additional Comments

@JTonda JTonda requested a review from zFernand0 October 11, 2023 15:04
@samadpls samadpls marked this pull request as ready for review October 17, 2023 15:00
@samadpls samadpls marked this pull request as draft October 17, 2023 15:01
@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ccd87be) 83.54% compared to head (f24a87e) 83.72%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
+ Coverage   83.54%   83.72%   +0.18%     
==========================================
  Files          34       34              
  Lines        2084     2108      +24     
==========================================
+ Hits         1741     1765      +24     
  Misses        343      343              
Flag Coverage Δ
unittests 83.72% <100.00%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aadityasinha-dotcom aadityasinha-dotcom marked this pull request as ready for review October 25, 2023 12:05
@aadityasinha-dotcom
Copy link
Contributor Author

@zFernand0 please review the changes ☺️

with open(self.original_file_path, 'r') as f:
original_config = commentjson.load(f)
original_config["$schema"] = "fixtures/invalid.zowe.schema.json"
with open(os.path.join(self.custom_dir, "invalid.zowe.config.json"), 'w') as f:
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 can't remove the files like invalid.zowe.config.json or invalidUri.zowe.config.json because other tests were failing

Copy link
Member

Choose a reason for hiding this comment

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

The other tests are probably failing because the setUp stage still expects the "invalid" files to exist:

self.fs.add_real_file(self.original_invalid_file_path)
self.fs.add_real_file(self.original_invalid_schema_file_path)
self.fs.add_real_file(self.original_invalidUri_file_path)
self.fs.add_real_file(self.original_invalidUri_schema_file_path)

I think this can be fixed by moving the add_real_file calls for invalid.zowe.config.json inside the specific tests where the files are created.

@t1m0thyj t1m0thyj self-requested a review November 6, 2023 15:11
with open(self.original_file_path, 'r') as f:
original_config = commentjson.load(f)
original_config["$schema"] = "fixtures/invalid.zowe.schema.json"
with open(os.path.join(self.custom_dir, "invalid.zowe.config.json"), 'w') as f:
Copy link
Member

Choose a reason for hiding this comment

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

The other tests are probably failing because the setUp stage still expects the "invalid" files to exist:

self.fs.add_real_file(self.original_invalid_file_path)
self.fs.add_real_file(self.original_invalid_schema_file_path)
self.fs.add_real_file(self.original_invalidUri_file_path)
self.fs.add_real_file(self.original_invalidUri_schema_file_path)

I think this can be fixed by moving the add_real_file calls for invalid.zowe.config.json inside the specific tests where the files are created.

Comment on lines +602 to +605
with open(self.original_schema_file_path, "r") as f:
original_schema = commentjson.load(f)
with open(os.path.join(self.custom_dir, "invalid.zowe.schema.json"), "w") as f:
commentjson.dump(original_schema, f)
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 have also made the invalid.zowe.schema.json, and made some changes to the config file dynamically ☺️

custom_dir = os.path.dirname(FIXTURES_PATH)
custom_file_path = os.path.join(custom_dir, "zowe.config.json")
os.chdir(custom_dir)
with open(path_to_config, "r") as f:
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 have also did the same thing for validate method tests

Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @aadityasinha-dotcom!

@t1m0thyj t1m0thyj requested a review from traeok December 1, 2023 14:42
@t1m0thyj t1m0thyj linked an issue Dec 1, 2023 that may be closed by this pull request
@t1m0thyj t1m0thyj merged commit 9cc18d9 into zowe:main Dec 1, 2023
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core] Dynamically generate invalid config files in unit tests
3 participants