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

Basic unit tests for operations #81

Merged
merged 17 commits into from
Jan 8, 2025
Merged
Prev Previous commit
Next Next commit
Added basic codeclimate test
  • Loading branch information
debonte committed Dec 11, 2024
commit 6772ed8d4d0ee4f32e97cd38d88aca93912dfa32
71 changes: 71 additions & 0 deletions tests/ops/codeclimate/test_codeclimate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import datetime
import json
import os
import tempfile

from sarif.operations import codeclimate_op
from sarif import sarif_file

INPUT_SARIF = {
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
"version": "2.1.0",
"runs": [
{
"tool": {"driver": {"name": "unit test"}},
"results": [
{
"ruleId": "CA2101",
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/Code/main.c",
"index": 0,
},
"region": {"startLine": 24, "startColumn": 9},
}
}
],
}
],
}
],
}


EXPECTED_OUTPUT_JSON = [
{
"type": "issue",
"check_name": "CA2101",
"description": "CA2101",
"categories": ["Bug Risk"],
"location": {
"path": "file:///C:/Code/main.c",
"lines": {"begin": 24},
},
"severity": "major",
"fingerprint": "e972b812ed32bf29ee306141244050b9",
}
]


def test_code_climate():
mtime = datetime.datetime.now()
input_sarif_file = sarif_file.SarifFile(
"SARIF_WITH_1_ISSUE", INPUT_SARIF, mtime=mtime
)

input_sarif_file_set = sarif_file.SarifFileSet()
input_sarif_file_set.files.append(input_sarif_file)

with tempfile.TemporaryDirectory() as tmp:
file_path = os.path.join(tmp, "codeclimate.json")
codeclimate_op.generate(
input_sarif_file_set, file_path, output_multiple_files=False
)

with open(file_path, "rb") as f_in:
output_json = json.load(f_in)

assert output_json == EXPECTED_OUTPUT_JSON
1 change: 0 additions & 1 deletion tests/ops/copy/test_copy_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import tempfile

import sarif
from sarif.operations import copy_op
from sarif import sarif_file
from tests.utils import get_sarif_schema
Expand Down