def test_streamthreshold_load(self): """test loading a stream threshold sketch from file""" md5_val = "fb1c39dd1a73f1ef0d7fc79f60fc028e" with NamedTemporaryFile(dir=os.getcwd(), suffix=".cms", delete=DELETE_TEMP_FILES) as fobj: st1 = StreamThreshold(threshold=10, width=1000, depth=5) self.assertEqual(st1.add("this is a test", 100), 100) self.assertEqual(st1.elements_added, 100) self.assertEqual(st1.meets_threshold, {"this is a test": 100}) st1.export(fobj.name) md5_out = calc_file_md5(fobj.name) self.assertEqual(md5_out, md5_val) # try loading directly to file! st2 = StreamThreshold(threshold=10, filepath=fobj.name) self.assertEqual(st2.width, 1000) self.assertEqual(st2.depth, 5) self.assertEqual(st2.elements_added, 100) self.assertEqual(st2.check("this is a test"), 100) # show on load that the tracking of stream threshold is gone self.assertEqual(st2.meets_threshold, dict()) self.assertEqual(st2.add("this is a test", 1), 101) self.assertEqual(st2.meets_threshold, {"this is a test": 101})
def test_streamthreshold_load(self): ''' test loading a stream threshold sketch from file ''' md5_val = '61d2ea9d0cb09b7bb284e1cf1a860449' filename = 'test.cms' st1 = StreamThreshold(threshold=10, width=1000, depth=5) self.assertEqual(st1.add('this is a test', 100), 100) self.assertEqual(st1.elements_added, 100) self.assertEqual(st1.meets_threshold, {'this is a test': 100}) st1.export(filename) md5_out = calc_file_md5(filename) self.assertEqual(md5_out, md5_val) # try loading directly to file! st2 = StreamThreshold(threshold=10, filepath=filename) self.assertEqual(st2.width, 1000) self.assertEqual(st2.depth, 5) self.assertEqual(st2.elements_added, 100) self.assertEqual(st2.check('this is a test'), 100) # show on load that the tracking of stream threshold is gone self.assertEqual(st2.meets_threshold, dict()) self.assertEqual(st2.add('this is a test', 1), 101) self.assertEqual(st2.meets_threshold, {'this is a test': 101}) os.remove(filename)