import tempfile from pathlib import Path import unittest import numpy as np import pandas as pd import pyarrow as pa import pyarrow.feather as feather from audit import raw_incident,population,save class AuditTests(unittest.TestCase): def test_raw_incident_union_keeps_self_loop_once(self): with tempfile.TemporaryDirectory(prefix='apl-scope-test-') as d: p=Path(d)/'raw.feather' frame=pd.DataFrame({'body_pre':[10,10,20,40],'body_post':[10,30,10,50],'weight':[1,2,3,4]},dtype=np.int64) feather.write_feather(pa.Table.from_pandas(frame,preserve_index=False),p,chunksize=2) result=raw_incident(p,np.array([10],np.uint64)) self.assertTrue(np.array_equal(result.to_numpy(),frame.iloc[:3].to_numpy())) with self.assertRaises(AssertionError): feather.write_feather(pa.table({'body_pre':[10],'wrong':[30],'weight':[1]}),p) raw_incident(p,np.array([10],np.uint64)) def test_population_does_not_equate_dopamine_to_DAN(self): m=pd.DataFrame({'annotation_class':[None,None,'ALPN','DAN'], 'annotation_type':['APL','DPM','VA6_adPN','PAM01']}) self.assertEqual(list(population(m)),['APL','DPM','ALPN','DAN']) def test_exclusive_output(self): with tempfile.TemporaryDirectory(prefix='apl-scope-test-') as d: p=Path(d)/'x.json';save(p,{'original':True}) with self.assertRaises(FileExistsError):save(p,{'original':False}) if __name__=='__main__':unittest.main()