Export tasks in a deterministic order (#3549)

fix issue #3527
This commit is contained in:
Will R S Hansen 2024-07-08 20:22:14 -07:00 committed by GitHub
parent 61c9b48664
commit 2bd609afe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 1 deletions

View file

@ -118,7 +118,7 @@ int CmdExport::execute (std::string& output)
// if no sort order, sort by id // if no sort order, sort by id
if (!sortOrder.size ()) { if (!sortOrder.size ()) {
reportSort = "id"; reportSort = "id,uuid";
} }
// Sort the tasks. // Sort the tasks.

View file

@ -170,6 +170,7 @@ set (pythonTests
tw-2575.test.py tw-2575.test.py
tw-262.test.py tw-262.test.py
tw-295.test.py tw-295.test.py
tw-3527.test.py
uda.test.py uda.test.py
uda_orphan.test.py uda_orphan.test.py
uda_report.test.py uda_report.test.py

39
test/tw-3527.test.py Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env python3
import sys
import os
import unittest
import re
import json
import string
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase
class TestExport(TestCase):
def setUp(self):
self.t = Task()
# pretty arbitrary, just need several unique tasks
for letter in string.ascii_lowercase:
self.t(f"add test_task +{letter}")
self.t(f"+{letter} done")
def test_export_stability_for_multiple_id_0(self):
exports = [self.t("export")[1] for _ in range(2)]
json_lists = [json.loads(s.strip()) for s in exports]
# to rule out a typo causing two failed exports
self.assertEqual(len(json_lists[0]), len(string.ascii_lowercase))
# for better diff view
self.assertEqual(json_lists[0], json_lists[1])
# the real test
self.assertEqual(exports[0], exports[1])
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())