optimization code added#2764
Open
fragan7dsouza wants to merge 1 commit into
Open
Conversation
|
@fragantrio is attempting to deploy a commit to the DeepSource Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR refactors gfi/test_data.py to reduce duplicated TOML/JSON parsing logic and to improve test assertions and error messages, addressing issue #2273 around robustness and maintainability of the data/labels sanity tests.
Changes:
- Added a shared
_load_file(...)helper to load/parse.tomland.jsonwith basic error handling. - Reworked tests to use
unittest.TestCaseassertion methods (instead of bareassert) and improved failure messages. - Improved duplicate-detection reporting by including the duplicate entries in the assertion message.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+19
to
+31
| _, ext = os.path.splitext(file_path) | ||
| try: | ||
| with open(file_path, "r", encoding="utf-8") as file_desc: | ||
| if ext.lower() == ".toml": | ||
| return toml.load(file_desc) | ||
| elif ext.lower() == ".json": | ||
| return json.load(file_desc) | ||
| else: | ||
| raise ValueError(f"Unsupported file format: {ext}") | ||
| except (json.JSONDecodeError, toml.TomlDecodeError) as err: | ||
| raise ValueError(f"Failed to parse {file_path}: {err}") from err | ||
| except Exception as err: | ||
| raise RuntimeError(f"Error reading file {file_path}: {err}") from err |
Comment on lines
+53
to
+56
| try: | ||
| data = _load_file(DATA_FILE_PATH) | ||
| except Exception as err: | ||
| self.fail(f"Failed to load or parse repository TOML: {err}") |
Comment on lines
+61
to
+64
| try: | ||
| data = _load_file(LABELS_FILE_PATH) | ||
| except Exception as err: | ||
| self.fail(f"Failed to load or parse labels JSON: {err}") |
Comment on lines
+69
to
+72
| try: | ||
| data = _load_file(DATA_FILE_PATH) | ||
| except Exception as err: | ||
| self.fail(f"Failed to load or parse repository TOML: {err}") |
Comment on lines
+39
to
+42
| self.assertTrue( | ||
| os.path.exists(DATA_FILE_PATH), | ||
| f"Repository TOML file does not exist at {DATA_FILE_PATH}" | ||
| ) |
Comment on lines
+46
to
+49
| self.assertTrue( | ||
| os.path.exists(LABELS_FILE_PATH), | ||
| f"Labels JSON file does not exist at {LABELS_FILE_PATH}" | ||
| ) |
Comment on lines
+75
to
+79
| self.assertEqual( | ||
| len(repos), | ||
| len(set(repos)), | ||
| f"Duplicate repository entries found: {duplicates}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
made changes for issue #2273