def test_load_smoketest(self): test_dict = {1:2, None:'a string'} t = tempfile.TemporaryFile(prefix='meliae-') # On some platforms TemporaryFile returns a wrapper object with 'file' # being the real object, on others, the returned object *is* the real # file object t_file = getattr(t, 'file', t) scanner.dump_all_referenced(t_file, test_dict) t_file.seek(0) manager = loader.load(t_file, show_prog=False) test_dict_id = id(test_dict) self.assertTrue(test_dict_id in manager.objs, '%s not found in %s' % (test_dict_id, manager.objs.keys()))
def test_load_smoketest(self): test_dict = {1:2, None:'a string'} t = tempfile.TemporaryFile(prefix='meliae-') # On some platforms TemporaryFile returns a wrapper object with 'file' # being the real object, on others, the returned object *is* the real # file object t_file = getattr(t, 'file', t) scanner.dump_all_referenced(t_file, test_dict) t_file.seek(0) manager = loader.load(t_file, show_prog=False) test_dict_id = id(test_dict) self.assertTrue(test_dict_id in manager.objs, '%s not found in %s' % (test_dict_id, list(manager.objs.keys())))
def test_largest_object_simple(self): output_file = self.get_temp_file() test_object = [1, 2, ['foo', 'spam']] scanner.dump_all_referenced(output_file, test_object) om = load_meliae(output_file) result = largest_object(om) largest_obj = result[0] self.assertEqual(largest_obj.get_type(), 'list') self.assertEqual(largest_obj.get_child_types(), ['int', 'list']) self.assertEqual(largest_obj.get_child_len(), 3)
def assertDumpAllReferenced(self, ref_objs, obj, is_pending=False): t = tempfile.TemporaryFile(prefix='meliae-') # On some platforms TemporaryFile returns a wrapper object with 'file' # being the real object, on others, the returned object *is* the real # file object t_file = getattr(t, 'file', t) scanner.dump_all_referenced(t_file, obj, is_pending=is_pending) t.flush() t.seek(0) # We don't care if the same entries are printed multiple times, just # that they are all correct lines = t.readlines() # py_dump_object_info will create a string that covers multpile lines, # so we need to split it back into 1-line-per-record ref_lines = [test__scanner.py_dump_object_info(ref_obj) for ref_obj in ref_objs] ref_lines = set(b''.join(ref_lines).splitlines(True)) self.assertEqual(sorted(ref_lines), sorted(lines))
def assertDumpAllReferenced(self, ref_objs, obj, is_pending=False): t = tempfile.TemporaryFile(prefix='meliae-') # On some platforms TemporaryFile returns a wrapper object with 'file' # being the real object, on others, the returned object *is* the real # file object t_file = getattr(t, 'file', t) scanner.dump_all_referenced(t_file, obj, is_pending=is_pending) t.flush() t.seek(0) # We don't care if the same entries are printed multiple times, just # that they are all correct lines = t.readlines() # py_dump_object_info will create a string that covers multpile lines, # so we need to split it back into 1-line-per-record ref_lines = [test__scanner.py_dump_object_info(ref_obj) for ref_obj in ref_objs] ref_lines = set(''.join(ref_lines).splitlines(True)) self.assertEqual(sorted(ref_lines), sorted(lines))