File size: 1,395 Bytes
dbbcf1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import importlib.util
import json
import unittest
from pathlib import Path

class ExportTests(unittest.TestCase):
    def module(self):
        self.assertIsNotNone(importlib.util.find_spec('export_results'))
        import export_results
        return export_results

    def test_whitelist_excludes_private_source_and_paths(self):
        src={'run_id':'fixture','completed':False,'elapsed_s':900,'errors':[{'error':'PRIVATE SOURCE /Users/person SECRET'}],'workspace':'SECRET','initial_input_tokens':25000,'visible_stream_tps':None}
        row=self.module().public_run(src)
        self.assertNotIn('SECRET',json.dumps(row));self.assertNotIn('/Users',json.dumps(row))
        self.assertFalse(row['completed']);self.assertIsNone(row['visible_stream_tps'])
        self.assertEqual(row['initial_input_tokens'],25000)

    def test_invalid_metric_or_identifier_rejected(self):
        m=self.module()
        for value in ['SECRET',float('nan'),True]:
            with self.assertRaises(ValueError):m.public_run({'run_id':'fixture','elapsed_s':value})
        with self.assertRaises(ValueError):m.public_run({'run_id':'/private/path'})

    def test_success_not_inferred_from_tests_only(self):
        r=self.module().public_run({'run_id':'fixture','completed':False,'gate_pass':True,'full_suite_pass':True})
        self.assertFalse(r['completed']);self.assertIsNone(r['visible_stream_tps'])