-
Notifications
You must be signed in to change notification settings - Fork 46
fix(test): update tests for entity class refactoring #623
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| from api import SourceAnalyzer, File, Struct, Function, Graph | ||
| from api import SourceAnalyzer, Graph | ||
|
|
||
|
|
||
| class Test_C_Analyzer(unittest.TestCase): | ||
| def test_analyzer(self): | ||
|
|
@@ -24,37 +25,44 @@ def test_analyzer(self): | |
| analyzer.analyze_local_folder(path, g) | ||
|
|
||
| f = g.get_file('', 'src.c', '.c') | ||
| self.assertEqual(File('', 'src.c', '.c'), f) | ||
| self.assertIsNotNone(f) | ||
| self.assertEqual(f.properties['name'], 'src.c') | ||
| self.assertEqual(f.properties['ext'], '.c') | ||
|
|
||
| s = g.get_struct_by_name('exp') | ||
| expected_s = Struct('src.c', 'exp', '', 9, 13) | ||
| expected_s.add_field('i', 'int') | ||
| expected_s.add_field('f', 'float') | ||
| expected_s.add_field('data', 'char[]') | ||
| self.assertEqual(expected_s, s) | ||
| self.assertIsNotNone(s) | ||
| self.assertEqual(s.properties['name'], 'exp') | ||
| self.assertEqual(s.properties['path'], 'src.c') | ||
|
Comment on lines
32
to
+35
|
||
| self.assertEqual(s.properties['src_start'], 9) | ||
| self.assertEqual(s.properties['src_end'], 13) | ||
| self.assertEqual(s.properties['fields'], [['i', 'int'], ['f', 'float'], ['data', 'char[]']]) | ||
|
|
||
| add = g.get_function_by_name('add') | ||
|
|
||
| expected_add = Function('src.c', 'add', '', 'int', '', 0, 7) | ||
| expected_add.add_argument('a', 'int') | ||
| expected_add.add_argument('b', 'int') | ||
| self.assertEqual(expected_add, add) | ||
| self.assertIn('a + b', add.src) | ||
| self.assertIsNotNone(add) | ||
| self.assertEqual(add.properties['name'], 'add') | ||
| self.assertEqual(add.properties['path'], 'src.c') | ||
| self.assertEqual(add.properties['ret_type'], 'int') | ||
| self.assertEqual(add.properties['src_start'], 0) | ||
| self.assertEqual(add.properties['src_end'], 7) | ||
| self.assertEqual(add.properties['args'], [['a', 'int'], ['b', 'int']]) | ||
| self.assertIn('a + b', add.properties['src']) | ||
|
|
||
| main = g.get_function_by_name('main') | ||
|
|
||
| expected_main = Function('src.c', 'main', '', 'int', '', 15, 18) | ||
| expected_main.add_argument('argv', 'const char**') | ||
| expected_main.add_argument('argc', 'int') | ||
| self.assertEqual(expected_main, main) | ||
| self.assertIn('x = add', main.src) | ||
| self.assertIsNotNone(main) | ||
| self.assertEqual(main.properties['name'], 'main') | ||
| self.assertEqual(main.properties['path'], 'src.c') | ||
| self.assertEqual(main.properties['ret_type'], 'int') | ||
| self.assertEqual(main.properties['src_start'], 15) | ||
| self.assertEqual(main.properties['src_end'], 18) | ||
| self.assertEqual(main.properties['args'], [['argv', 'const char**'], ['argc', 'int']]) | ||
| self.assertIn('x = add', main.properties['src']) | ||
|
|
||
| callees = g.function_calls(main.id) | ||
| self.assertEqual(len(callees), 1) | ||
| self.assertEqual(callees[0], add) | ||
|
|
||
| callers = g.function_called_by(add.id) | ||
| callers = [caller.name for caller in callers] | ||
| callers = [caller.properties['name'] for caller in callers] | ||
|
|
||
| self.assertEqual(len(callers), 2) | ||
| self.assertIn('add', callers) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |||||||
| import unittest | ||||||||
| from pathlib import Path | ||||||||
|
|
||||||||
| from api import SourceAnalyzer, File, Class, Function, Graph | ||||||||
| from api import SourceAnalyzer, Graph | ||||||||
|
|
||||||||
|
|
||||||||
| class Test_PY_Analyzer(unittest.TestCase): | ||||||||
| def test_analyzer(self): | ||||||||
|
|
@@ -15,7 +16,7 @@ def test_analyzer(self): | |||||||
| # Get the directory of the current file | ||||||||
| current_dir = os.path.dirname(current_file_path) | ||||||||
|
|
||||||||
| # Append 'source_files/c' to the current directory | ||||||||
| # Append 'source_files/py' to the current directory | ||||||||
| path = os.path.join(current_dir, 'source_files') | ||||||||
| path = os.path.join(path, 'py') | ||||||||
| path = str(path) | ||||||||
|
|
@@ -24,37 +25,50 @@ def test_analyzer(self): | |||||||
| analyzer.analyze_local_folder(path, g) | ||||||||
|
|
||||||||
| f = g.get_file('', 'src.py', '.py') | ||||||||
|
||||||||
| f = g.get_file('', 'src.py', '.py') | |
| src_file_path = os.path.join(path, 'src.py') | |
| f = g.get_file(src_file_path, 'src.py', '.py') |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assertions assume metadata like ret_type and args are present on Function nodes and that path == 'src.py'. In the current analysis pipeline, entities are created via graph.add_entity(..., props={}) (no ret_type/args), and path is set from str(file.path) (typically an absolute path). This will raise KeyError/fail in a fresh DB. Consider asserting only on guaranteed properties (name, path, src_start, src_end, doc) or updating the analyzer to populate these properties before asserting on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Graph.add_file()persists file nodes withpath=str(file.path)(full file path). Usingg.get_file('', 'src.c', '.c')will not match that representation on a clean graph. Update the test to query using the same storedpathvalue (or change the storage/query convention sopathis directory-only andnameis basename).