Lines Matching refs:self
408 def tearDown(self):
414 def _create(self, fmt=None):
441 def test_create(self):
442 pl = self._create()
443 self.assertEqual(pl["aString"], "Doodah")
444 self.assertEqual(pl["aDict"]["aFalseValue"], False)
446 def test_io(self):
447 pl = self._create()
454 self.assertEqual(dict(pl), dict(pl2))
456 self.assertRaises(AttributeError, plistlib.dump, pl, 'filename')
457 self.assertRaises(AttributeError, plistlib.load, 'filename')
459 def test_invalid_type(self):
463 with self.subTest(fmt=fmt):
464 self.assertRaises(TypeError, plistlib.dumps, pl, fmt=fmt)
466 def test_invalid_uid(self):
467 with self.assertRaises(TypeError):
469 with self.assertRaises(ValueError):
471 with self.assertRaises(ValueError):
474 def test_int(self):
478 with self.subTest(pl=pl, fmt=fmt):
481 self.assertIsInstance(pl2, int)
482 self.assertEqual(pl, pl2)
484 self.assertEqual(data, data2)
488 with self.subTest(pl=pl, fmt=fmt):
489 self.assertRaises(OverflowError, plistlib.dumps,
492 def test_bytearray(self):
495 with self.subTest(pl=pl, fmt=fmt):
498 self.assertIsInstance(pl2, bytes)
499 self.assertEqual(pl2, pl)
501 self.assertEqual(data, data2)
503 def test_bytes(self):
504 pl = self._create()
507 self.assertEqual(dict(pl), dict(pl2))
509 self.assertEqual(data, data2)
511 def test_indentation_array(self):
513 self.assertEqual(plistlib.loads(plistlib.dumps(data)), data)
515 def test_indentation_dict(self):
517 self.assertEqual(plistlib.loads(plistlib.dumps(data)), data)
519 def test_indentation_dict_mix(self):
521 self.assertEqual(plistlib.loads(plistlib.dumps(data)), data)
523 def test_uid(self):
525 self.assertEqual(plistlib.loads(plistlib.dumps(data, fmt=plistlib.FMT_BINARY)), data)
534 self.assertEqual(plistlib.loads(plistlib.dumps(dict_data, fmt=plistlib.FMT_BINARY)), dict_data)
536 def test_uid_data(self):
538 self.assertEqual(uid.data, 1)
540 def test_uid_eq(self):
541 self.assertEqual(UID(1), UID(1))
542 self.assertNotEqual(UID(1), UID(2))
543 self.assertNotEqual(UID(1), "not uid")
545 def test_uid_hash(self):
546 self.assertEqual(hash(UID(1)), hash(UID(1)))
548 def test_uid_repr(self):
549 self.assertEqual(repr(UID(1)), "UID(1)")
551 def test_uid_index(self):
552 self.assertEqual(operator.index(UID(1)), 1)
554 def test_uid_pickle(self):
556 self.assertEqual(pickle.loads(pickle.dumps(UID(19), protocol=proto)), UID(19))
558 def test_uid_copy(self):
559 self.assertEqual(copy.copy(UID(1)), UID(1))
560 self.assertEqual(copy.deepcopy(UID(1)), UID(1))
562 def test_appleformatting(self):
564 with self.subTest(fmt=fmt):
567 self.assertEqual(data, TESTDATA[fmt],
571 def test_appleformattingfromliteral(self):
572 self.maxDiff = None
574 with self.subTest(fmt=fmt):
575 pl = self._create(fmt=fmt)
577 self.assertEqual(dict(pl), dict(pl2),
580 self.assertEqual(dict(pl), dict(pl2),
583 def test_bytesio(self):
585 with self.subTest(fmt=fmt):
587 pl = self._create(fmt=fmt)
590 self.assertEqual(dict(pl), dict(pl2))
592 self.assertEqual(dict(pl), dict(pl2))
594 def test_keysort_bytesio(self):
602 with self.subTest(fmt=fmt, sort_keys=sort_keys):
609 self.assertEqual(dict(pl), dict(pl2))
611 self.assertEqual(list(pl2.keys()), ['a', 'b', 'c'])
613 self.assertEqual(list(pl2.keys()), ['b', 'a', 'c'])
615 def test_keysort(self):
623 with self.subTest(fmt=fmt, sort_keys=sort_keys):
627 self.assertEqual(dict(pl), dict(pl2))
629 self.assertEqual(list(pl2.keys()), ['a', 'b', 'c'])
631 self.assertEqual(list(pl2.keys()), ['b', 'a', 'c'])
633 def test_keys_no_string(self):
637 with self.subTest(fmt=fmt):
638 self.assertRaises(TypeError, plistlib.dumps, pl, fmt=fmt)
641 self.assertRaises(TypeError, plistlib.dump, pl, b, fmt=fmt)
643 def test_skipkeys(self):
650 with self.subTest(fmt=fmt):
655 self.assertEqual(pl2, {'snake': 'aWord'})
662 self.assertEqual(pl2, {'snake': 'aWord'})
664 def test_tuple_members(self):
672 with self.subTest(fmt=fmt):
675 self.assertEqual(pl2, {
681 self.assertIsNot(pl2['first'], pl2['second'])
683 def test_list_members(self):
691 with self.subTest(fmt=fmt):
694 self.assertEqual(pl2, {
699 self.assertIsNot(pl2['first'], pl2['second'])
701 def test_dict_members(self):
709 with self.subTest(fmt=fmt):
712 self.assertEqual(pl2, {
717 self.assertIsNot(pl2['first'], pl2['second'])
719 def test_controlcharacters(self):
727 self.assertEqual(plistlib.loads(data), testString)
729 with self.assertRaises(ValueError):
733 def test_non_bmp_characters(self):
736 with self.subTest(fmt=fmt):
738 self.assertEqual(plistlib.loads(data), pl)
740 def test_lone_surrogates(self):
742 with self.subTest(fmt=fmt):
743 with self.assertRaises(UnicodeEncodeError):
745 with self.assertRaises(UnicodeEncodeError):
748 def test_nondictroot(self):
750 with self.subTest(fmt=fmt):
755 self.assertEqual(test1, result1)
756 self.assertEqual(test2, result2)
758 def test_invalidarray(self):
762 self.assertRaises(ValueError, plistlib.loads,
765 def test_invaliddict(self):
771 self.assertRaises(ValueError, plistlib.loads,
773 self.assertRaises(ValueError, plistlib.loads,
776 def test_invalidinteger(self):
777 self.assertRaises(ValueError, plistlib.loads,
780 def test_invalidreal(self):
781 self.assertRaises(ValueError, plistlib.loads,
784 def test_integer_notations(self):
787 self.assertEqual(value, 456)
791 self.assertEqual(value, 10)
795 self.assertEqual(value, 123)
797 def test_xml_encodings(self):
809 pl = self._create(fmt=plistlib.FMT_XML)
810 with self.subTest(encoding=encoding):
814 self.assertEqual(dict(pl), dict(pl2))
816 def test_dump_invalid_format(self):
817 with self.assertRaises(ValueError):
820 def test_load_invalid_file(self):
821 with self.assertRaises(plistlib.InvalidFileException):
824 def test_modified_uid_negative(self):
827 with self.assertRaises(ValueError):
830 def test_modified_uid_huge(self):
833 with self.assertRaises(OverflowError):
836 def test_xml_plist_with_entity_decl(self):
837 with self.assertRaisesRegex(plistlib.InvalidFileException,
859 def test_nonstandard_refs_size(self):
869 self.assertEqual(plistlib.loads(data), {'a': 'b'})
871 def test_dump_duplicates(self):
876 with self.subTest(x=x):
878 self.assertLess(len(data), 1100, repr(data))
880 def test_identity(self):
884 with self.subTest(x=x):
889 self.assertEqual(a, x)
890 self.assertEqual(b, x)
891 self.assertIs(a, b)
893 def test_cycles(self):
898 self.assertIs(b[0], b)
903 self.assertIs(b[0][0], b)
908 self.assertIs(b['x'], b)
910 def test_deep_nesting(self):
914 result = self.decode(*chunks, b'\x54seed', offset_size=4, ref_size=4)
919 self.assertIsInstance(result, list)
920 self.assertEqual(len(result), 1)
922 self.assertEqual(result, 'seed')
924 def test_large_timestamp(self):
927 with self.subTest(ts=ts):
931 self.assertEqual(plistlib.loads(data), d)
933 def test_load_singletons(self):
934 self.assertIs(self.decode(b'\x00'), None)
935 self.assertIs(self.decode(b'\x08'), False)
936 self.assertIs(self.decode(b'\x09'), True)
937 self.assertEqual(self.decode(b'\x0f'), b'')
939 def test_load_int(self):
940 self.assertEqual(self.decode(b'\x10\x00'), 0)
941 self.assertEqual(self.decode(b'\x10\xfe'), 0xfe)
942 self.assertEqual(self.decode(b'\x11\xfe\xdc'), 0xfedc)
943 self.assertEqual(self.decode(b'\x12\xfe\xdc\xba\x98'), 0xfedcba98)
944 self.assertEqual(self.decode(b'\x13\x01\x23\x45\x67\x89\xab\xcd\xef'),
946 self.assertEqual(self.decode(b'\x13\xfe\xdc\xba\x98\x76\x54\x32\x10'),
949 def test_unsupported(self):
955 with self.subTest(f'token {token:02x}'):
956 with self.assertRaises(plistlib.InvalidFileException):
957 self.decode(bytes([token]) + b'\x00'*16)
959 def test_invalid_binary(self):
961 with self.subTest(name):
962 with self.assertRaises(plistlib.InvalidFileException):
967 def test_keyed_archive_data(self):
995 self.assertEqual(plistlib.loads(TESTDATA["KEYED_ARCHIVE"]), data)
999 def test__all__(self):
1001 support.check__all__(self, plistlib, not_exported=not_exported)
1031 def get_lint_status(self):
1032 return subprocess.run(['plutil', "-lint", self.file_name], capture_output=True, text=True).stdout
1034 def convert_to_json(self):
1037 subprocess.run(['plutil', "-convert", 'json', self.file_name])
1039 def convert_to_bin(self):
1042 subprocess.run(['plutil', "-convert", 'binary1', self.file_name])
1044 def write_pl(self):
1047 with open(self.file_name, 'wb') as f:
1048 plistlib.dump(self.pl, f, fmt=plistlib.FMT_BINARY)
1050 def test_lint_status(self):
1052 self.assertEqual(f"{self.file_name}: OK\n", self.get_lint_status())
1054 def check_content(self):
1056 self.convert_to_json()
1057 with open(self.file_name) as f:
1059 self.assertEqual(ff, self.exptected_properties)
1061 def check_plistlib_parse(self):
1063 self.convert_to_bin()
1064 with open(self.file_name, 'rb') as f:
1065 self.assertEqual(plistlib.load(f), self.exptected_properties)
1067 def test_octal_and_hex(self):
1068 self.write_pl()
1069 self.convert_to_json()
1070 with open(self.file_name, 'r') as f:
1072 self.assertEqual(p.get("HexType"), 16777228)
1073 self.assertEqual(p.get("IntType"), 83)