Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_filename():
diff_and_sc = {
'diff': '',
'source_code': '',
'source_code_before': ''
}
m1 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m3 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m2 = Modification('dspadini/pydriller/myfile.py',
None,
ModificationType.ADD, diff_and_sc)
assert m1.filename == 'mynewfile.py'
assert m2.filename == 'myfile.py'
assert m1 != m2
assert m3 == m1
def test_filename():
diff_and_sc = {
'diff': '',
'source_code': '',
'source_code_before': ''
}
m1 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m3 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m2 = Modification('dspadini/pydriller/myfile.py',
None,
ModificationType.ADD, diff_and_sc)
assert m1.filename == 'mynewfile.py'
assert m2.filename == 'myfile.py'
assert m1 != m2
assert m3 == m1
def test_metrics_java():
with open('test-repos/test6/FileJava.java') as f:
sc = f.read()
diff_and_sc = {
'diff': '',
'source_code': sc,
'source_code_before': sc
}
m1 = Modification('test-repos/test6/FileJava.java',
"test-repos/test6/FileJava.java",
ModificationType.MODIFY, diff_and_sc)
assert m1.nloc == 466
assert m1.token_count == 3809
assert m1.complexity == 92
assert len(m1.methods) == 46
def test_metrics_not_supported_file():
sc = 'asd !&%@*&^@\n jjdkj'
diff_and_sc = {
'diff': '',
'source_code': sc,
'source_code_before': sc
}
m1 = Modification('test-repos/test6/NotSupported.pdf',
"test-repos/test6/NotSupported.pdf",
ModificationType.MODIFY, diff_and_sc)
assert m1.nloc == 2
assert len(m1.methods) == 0
def test_filename():
diff_and_sc = {
'diff': '',
'source_code': '',
'source_code_before': ''
}
m1 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m3 = Modification('dspadini/pydriller/myfile.py',
'dspadini/pydriller/mynewfile.py',
ModificationType.ADD, diff_and_sc)
m2 = Modification('dspadini/pydriller/myfile.py',
None,
ModificationType.ADD, diff_and_sc)
assert m1.filename == 'mynewfile.py'
assert m2.filename == 'myfile.py'
assert m1 != m2
assert m3 == m1
def test_metrics_python():
with open('test-repos/test6/git_repository.py') as f:
sc = f.read()
diff_and_sc = {
'diff': '',
'source_code': sc,
'source_code_before': sc
}
m1 = Modification('test-repos/test6/git_repository.py',
"test-repos/test6/git_repository.py",
ModificationType.MODIFY, diff_and_sc)
assert m1.nloc == 196
assert m1.token_count == 1009
assert m1.complexity == 43
assert len(m1.methods) == 19
def __eq__(self, other):
if not isinstance(other, Modification):
return NotImplemented
if self is other:
return True
return self.__dict__ == other.__dict__
def _parse_diff(self, diff_index) -> List[Modification]:
modifications_list = []
for diff in diff_index:
old_path = diff.a_path
new_path = diff.b_path
change_type = self._from_change_to_modification_type(diff)
diff_and_sc = {
'diff': self._get_decoded_str(diff.diff),
'source_code_before': self._get_decoded_sc_str(
diff.a_blob),
'source_code': self._get_decoded_sc_str(
diff.b_blob)
}
modifications_list.append(Modification(old_path, new_path,
change_type, diff_and_sc))
return modifications_list