Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
priitlatt committed Oct 17, 2024
1 parent d115c03 commit 8ced5b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 222 deletions.
13 changes: 13 additions & 0 deletions tests/models/xctests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import pathlib
from typing import Dict

import pytest
from codemagic.models.xctests.xcresult import ActionsInvocationRecord
Expand All @@ -15,3 +16,15 @@ def action_invocations_record(mocks_dir) -> ActionsInvocationRecord:
with (mocks_dir / "actions_invocation_record.json").open() as fd:
data = json.load(fd)
return ActionsInvocationRecord(data, pathlib.Path("Test.xcresult"))


@pytest.fixture
def test_results_summary_dict(mocks_dir) -> Dict:
mock_path = mocks_dir / "test_results_summary.json"
return json.loads(mock_path.read_text())


@pytest.fixture
def test_results_tests_dict(mocks_dir) -> Dict:
mock_path = mocks_dir / "test_results_tests.json"
return json.loads(mock_path.read_text())
214 changes: 8 additions & 206 deletions tests/models/xctests/converter/test_xcode_16_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,210 +13,6 @@
from codemagic.models.xctests.converter import Xcode16XcResultConverter


def _get_test_report_tests(_):
return {
"devices": [
{
"architecture": "arm64",
"deviceId": "D4A58F38-8890-43BE-93F9-3D268010475D",
"deviceName": "iPhone SE (3rd generation)",
"modelName": "iPhone SE (3rd generation)",
"osVersion": "18.0",
"platform": "iOS Simulator",
},
],
"testNodes": [
{
"children": [
{
"children": [
{
"children": [
{
"duration": "0,0011s",
"name": "testDisabledExample()",
"nodeIdentifier": "banaanTests/testDisabledExample()",
"nodeType": "Test Case",
"result": "Passed",
},
{
"duration": "0,00045s",
"name": "testExample()",
"nodeIdentifier": "banaanTests/testExample()",
"nodeType": "Test Case",
"result": "Passed",
},
{
"children": [
{
"name": 'banaanTests.swift:50: failed: caught error: "badInput"',
"nodeType": "Failure Message",
"result": "Failed",
},
],
"duration": "0,2s",
"name": "testExceptionExample()",
"nodeIdentifier": "banaanTests/testExceptionExample()",
"nodeType": "Test Case",
"result": "Failed",
},
{
"children": [
{
"name": "banaanTests.swift:44: failed - This won't make the cut",
"nodeType": "Failure Message",
"result": "Failed",
},
],
"duration": "0,002s",
"name": "testFailExample()",
"nodeIdentifier": "banaanTests/testFailExample()",
"nodeType": "Test Case",
"result": "Failed",
},
{
"duration": "0,26s",
"name": "testPerformanceExample()",
"nodeIdentifier": "banaanTests/testPerformanceExample()",
"nodeType": "Test Case",
"result": "Passed",
},
{
"children": [
{
"name": "Test skipped - This test is skipped",
"nodeType": "Failure Message",
"result": "Skipped",
},
],
"duration": "0,0052s",
"name": "testSkippedExample()",
"nodeIdentifier": "banaanTests/testSkippedExample()",
"nodeType": "Test Case",
"result": "Skipped",
},
],
"name": "banaanTests",
"nodeType": "Test Suite",
"result": "Failed",
},
],
"name": "banaanTests",
"nodeType": "Unit test bundle",
"result": "Failed",
},
{
"children": [
{
"children": [
{
"duration": "2s",
"name": "testUIExample()",
"nodeIdentifier": "banaanUITests/testUIExample()",
"nodeType": "Test Case",
"result": "Passed",
},
{
"children": [
{
"name": "banaanUITests.swift:40: failed - Bad UI",
"nodeType": "Failure Message",
"result": "Failed",
},
],
"duration": "3s",
"name": "testUIFailExample()",
"nodeIdentifier": "banaanUITests/testUIFailExample()",
"nodeType": "Test Case",
"result": "Failed",
},
],
"name": "banaanUITests",
"nodeType": "Test Suite",
"result": "Failed",
},
],
"name": "banaanUITests",
"nodeType": "UI test bundle",
"result": "Failed",
},
],
"name": "banaan",
"nodeType": "Test Plan",
"result": "Failed",
},
],
"testPlanConfigurations": [
{
"configurationId": "1",
"configurationName": "Test Scheme Action",
},
],
}


def _get_test_report_summary(_):
return {
"devicesAndConfigurations": [
{
"device": {
"architecture": "arm64",
"deviceId": "D4A58F38-8890-43BE-93F9-3D268010475D",
"deviceName": "iPhone SE (3rd generation)",
"modelName": "iPhone SE (3rd generation)",
"osVersion": "18.0",
"platform": "iOS Simulator",
},
"expectedFailures": 0,
"failedTests": 3,
"passedTests": 4,
"skippedTests": 1,
"testPlanConfiguration": {
"configurationId": "1",
"configurationName": "Test Scheme Action",
},
},
],
"environmentDescription": "banaan · Built with macOS 14.7",
"expectedFailures": 0,
"failedTests": 3,
"finishTime": 1728473305.128,
"passedTests": 4,
"result": "Failed",
"skippedTests": 1,
"startTime": 1728473222.071,
"statistics": [
{
"subtitle": "1 test run",
"title": "1 test collected performance metrics",
},
],
"testFailures": [
{
"failureText": 'failed: caught error: "badInput"',
"targetName": "banaanTests",
"testIdentifier": 3,
"testName": "testExceptionExample()",
},
{
"failureText": "failed - This won't make the cut",
"targetName": "banaanTests",
"testIdentifier": 4,
"testName": "testFailExample()",
},
{
"failureText": "failed - Bad UI",
"targetName": "banaanUITests",
"testIdentifier": 8,
"testName": "testUIFailExample()",
},
],
"title": "Test - banaan",
"topInsights": [],
"totalTestCount": 8,
}


@pytest.fixture
def expected_properties() -> List[Property]:
return [
Expand All @@ -230,8 +26,14 @@ def expected_properties() -> List[Property]:
]


@mock.patch.object(XcResultTool, "get_test_report_tests", _get_test_report_tests)
@mock.patch.object(XcResultTool, "get_test_report_summary", _get_test_report_summary)
@pytest.fixture(autouse=True)
def patch_xcresulttool(test_results_summary_dict, test_results_tests_dict):
mock_tests = mock.patch.object(XcResultTool, "get_test_report_tests", lambda _: test_results_tests_dict)
mock_summary = mock.patch.object(XcResultTool, "get_test_report_summary", lambda _: test_results_summary_dict)
with mock_tests, mock_summary:
yield


@mock.patch("codemagic.models.xctests.converter.datetime")
def test_converter(mock_datetime, expected_properties):
mock_datetime.fromtimestamp.return_value = datetime(2024, 10, 15, tzinfo=timezone.utc)
Expand Down
16 changes: 0 additions & 16 deletions tests/models/xctests/xcresult/test_xcode_16_xcresult.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import json
from typing import Dict

import pytest
from codemagic.models.xctests.xcresult import XcTestNode
from codemagic.models.xctests.xcresult import XcTestNodeType
from codemagic.models.xctests.xcresult.xcode_16_xcresult import XcConfiguration
Expand All @@ -14,18 +10,6 @@
from codemagic.models.xctests.xcresult.xcode_16_xcresult import XcTestStatistic


@pytest.fixture
def test_results_summary_dict(mocks_dir) -> Dict:
mock_path = mocks_dir / "test_results_summary.json"
return json.loads(mock_path.read_text())


@pytest.fixture
def test_results_tests_dict(mocks_dir) -> Dict:
mock_path = mocks_dir / "test_results_tests.json"
return json.loads(mock_path.read_text())


def test_load_test_results_summary(test_results_summary_dict):
test_results_summary = XcSummary.from_dict(test_results_summary_dict)

Expand Down

0 comments on commit 8ced5b1

Please sign in to comment.