Skip to content

optimization code added#2764

Open
fragan7dsouza wants to merge 1 commit into
DeepSourceCorp:masterfrom
fragan7dsouza:refactor-data-tests
Open

optimization code added#2764
fragan7dsouza wants to merge 1 commit into
DeepSourceCorp:masterfrom
fragan7dsouza:refactor-data-tests

Conversation

@fragan7dsouza

Copy link
Copy Markdown

made changes for issue #2273

Copilot AI review requested due to automatic review settings June 23, 2026 07:38
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

@fragantrio is attempting to deploy a commit to the DeepSource Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 .toml and .json with basic error handling.
  • Reworked tests to use unittest.TestCase assertion methods (instead of bare assert) 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 thread gfi/test_data.py
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 thread gfi/test_data.py
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 thread gfi/test_data.py
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 thread gfi/test_data.py
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 thread gfi/test_data.py
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 thread gfi/test_data.py
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 thread gfi/test_data.py
Comment on lines +75 to +79
self.assertEqual(
len(repos),
len(set(repos)),
f"Duplicate repository entries found: {duplicates}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants