Ejemplo n.º 1
0
    def test_dyld_framework(self):
        for k in (
            "DYLD_FRAMEWORK_PATH",
            "DYLD_FALLBACK_FRAMEWORK_PATH",
            "DYLD_IMAGE_SUFFIX",
        ):
            if k in os.environ:
                del os.environ[k]

        orig = os.path.exists
        try:
            os.path.exists = lambda fn: l.append(fn)

            self.maxDiff = None

            l = []
            self.assertRaises(
                ImportError,
                dyld.dyld_framework,
                "/System/Library/Cocoa.framework/Cocoa",
                "XCocoa",
            )
            self.assertEqual(
                l,
                [
                    "/System/Library/Cocoa.framework/Cocoa",
                    os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                    "/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/System/Library/Frameworks/XCocoa.framework/XCocoa",
                ],
            )

            os.environ["DYLD_IMAGE_SUFFIX"] = "_profile"
            l = []
            self.assertRaises(
                ImportError,
                dyld.dyld_framework,
                "/System/Library/Cocoa.framework/Cocoa",
                "XCocoa",
            )
            self.assertEqual(
                l,
                [
                    "/System/Library/Cocoa.framework/Cocoa_profile",
                    "/System/Library/Cocoa.framework/Cocoa",
                    os.path.expanduser(
                        "~/Library/Frameworks/XCocoa.framework/XCocoa_profile"
                    ),
                    os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                    "/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                    "/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/Network/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                    "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/System/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                    "/System/Library/Frameworks/XCocoa.framework/XCocoa",
                ],
            )
            del os.environ["DYLD_IMAGE_SUFFIX"]

            os.environ["DYLD_FRAMEWORK_PATH"] = "/Projects/Frameworks:/Company"
            l = []
            self.assertRaises(
                ImportError,
                dyld.dyld_framework,
                "/System/Library/Cocoa.framework/Cocoa",
                "XCocoa",
            )
            self.assertEqual(
                l,
                [
                    "/Projects/Frameworks/XCocoa.framework/XCocoa",
                    "/Company/XCocoa.framework/XCocoa",
                    "/System/Library/Cocoa.framework/Cocoa",
                    os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                    "/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                    "/System/Library/Frameworks/XCocoa.framework/XCocoa",
                ],
            )
            del os.environ["DYLD_FRAMEWORK_PATH"]

            os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"] = "/Projects/Frameworks:/Company"
            l = []
            self.assertRaises(
                ImportError,
                dyld.dyld_framework,
                "/System/Library/Cocoa.framework/Cocoa",
                "XCocoa",
            )
            self.assertEqual(
                l,
                [
                    "/System/Library/Cocoa.framework/Cocoa",
                    "/Projects/Frameworks/XCocoa.framework/XCocoa",
                    "/Company/XCocoa.framework/XCocoa",
                ],
            )
            del os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"]

            os.environ["DYLD_FRAMEWORK_PATH"] = "/Prefix1:/Prefix2"
            os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"] = "/Suffix1:/Suffix2"
            os.environ["DYLD_IMAGE_SUFFIX"] = "_debug"

            l = []
            self.assertRaises(
                ImportError,
                dyld.dyld_framework,
                "/System/Library/Cocoa.framework/Cocoa",
                "XCocoa",
                "B",
            )
            self.assertEqual(
                l,
                [
                    "/Prefix1/XCocoa.framework/Versions/B/XCocoa_debug",
                    "/Prefix1/XCocoa.framework/Versions/B/XCocoa",
                    "/Prefix2/XCocoa.framework/Versions/B/XCocoa_debug",
                    "/Prefix2/XCocoa.framework/Versions/B/XCocoa",
                    "/System/Library/Cocoa.framework/Cocoa_debug",
                    "/System/Library/Cocoa.framework/Cocoa",
                    "/Suffix1/XCocoa.framework/Versions/B/XCocoa_debug",
                    "/Suffix1/XCocoa.framework/Versions/B/XCocoa",
                    "/Suffix2/XCocoa.framework/Versions/B/XCocoa_debug",
                    "/Suffix2/XCocoa.framework/Versions/B/XCocoa",
                ],
            )
            del os.environ["DYLD_FRAMEWORK_PATH"]
            del os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"]
            del os.environ["DYLD_IMAGE_SUFFIX"]

        finally:
            os.path.exists = orig

        self.assertEqual(
            dyld.dyld_framework("/System/Library/Cocoa.framework/Cocoa", "Cocoa"),
            "/System/Library/Frameworks/Cocoa.framework/Cocoa",
        )
        self.assertEqual(
            dyld.dyld_framework("/System/Library/Cocoa.framework/Cocoa", "Cocoa", "A"),
            "/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa",
        )
Ejemplo n.º 2
0
    def test_dyld_framework(self):
        for k in ('DYLD_FRAMEWORK_PATH', 'DYLD_FALLBACK_FRAMEWORK_PATH', 'DYLD_IMAGE_SUFFIX'):
            if k in os.environ:
                del os.environ[k]

        orig = os.path.exists
        try:
            os.path.exists = lambda fn: l.append(fn)

            self.maxDiff = None

            l = []
            self.assertRaises(ImportError, dyld.dyld_framework, "/System/Library/Cocoa.framework/Cocoa", "XCocoa")
            self.assertEqual(l, [
                "/System/Library/Cocoa.framework/Cocoa",
                os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                "/Library/Frameworks/XCocoa.framework/XCocoa",
                "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                "/System/Library/Frameworks/XCocoa.framework/XCocoa",
            ])

            os.environ["DYLD_IMAGE_SUFFIX"] = "_profile"
            l = []
            self.assertRaises(ImportError, dyld.dyld_framework, "/System/Library/Cocoa.framework/Cocoa", "XCocoa")
            self.assertEqual(l, [
                "/System/Library/Cocoa.framework/Cocoa_profile",
                "/System/Library/Cocoa.framework/Cocoa",
                os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa_profile"),
                os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                "/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                "/Library/Frameworks/XCocoa.framework/XCocoa",
                "/Network/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                "/System/Library/Frameworks/XCocoa.framework/XCocoa_profile",
                "/System/Library/Frameworks/XCocoa.framework/XCocoa",
            ])
            del os.environ["DYLD_IMAGE_SUFFIX"]

            os.environ["DYLD_FRAMEWORK_PATH"] = "/Projects/Frameworks:/Company"
            l = []
            self.assertRaises(ImportError, dyld.dyld_framework, "/System/Library/Cocoa.framework/Cocoa", "XCocoa")
            self.assertEqual(l, [
                "/Projects/Frameworks/XCocoa.framework/XCocoa",
                "/Company/XCocoa.framework/XCocoa",
                "/System/Library/Cocoa.framework/Cocoa",
                os.path.expanduser("~/Library/Frameworks/XCocoa.framework/XCocoa"),
                "/Library/Frameworks/XCocoa.framework/XCocoa",
                "/Network/Library/Frameworks/XCocoa.framework/XCocoa",
                "/System/Library/Frameworks/XCocoa.framework/XCocoa",
            ])
            del os.environ["DYLD_FRAMEWORK_PATH"]

            os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"] = "/Projects/Frameworks:/Company"
            l = []
            self.assertRaises(ImportError, dyld.dyld_framework, "/System/Library/Cocoa.framework/Cocoa", "XCocoa")
            self.assertEqual(l, [
                "/System/Library/Cocoa.framework/Cocoa",
                "/Projects/Frameworks/XCocoa.framework/XCocoa",
                "/Company/XCocoa.framework/XCocoa",
            ])
            del os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"]

            os.environ["DYLD_FRAMEWORK_PATH"] = "/Prefix1:/Prefix2"
            os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"] = "/Suffix1:/Suffix2"
            os.environ["DYLD_IMAGE_SUFFIX"] = "_debug"

            l = []
            self.assertRaises(ImportError, dyld.dyld_framework, "/System/Library/Cocoa.framework/Cocoa", "XCocoa", "B")
            self.assertEqual(l, [
                "/Prefix1/XCocoa.framework/Versions/B/XCocoa_debug",
                "/Prefix1/XCocoa.framework/Versions/B/XCocoa",
                "/Prefix2/XCocoa.framework/Versions/B/XCocoa_debug",
                "/Prefix2/XCocoa.framework/Versions/B/XCocoa",
                "/System/Library/Cocoa.framework/Cocoa_debug",
                "/System/Library/Cocoa.framework/Cocoa",
                "/Suffix1/XCocoa.framework/Versions/B/XCocoa_debug",
                "/Suffix1/XCocoa.framework/Versions/B/XCocoa",
                "/Suffix2/XCocoa.framework/Versions/B/XCocoa_debug",
                "/Suffix2/XCocoa.framework/Versions/B/XCocoa",
            ])
            del os.environ["DYLD_FRAMEWORK_PATH"]
            del os.environ["DYLD_FALLBACK_FRAMEWORK_PATH"]
            del os.environ["DYLD_IMAGE_SUFFIX"]


        finally:
            os.path.exists = orig

        self.assertEqual(dyld.dyld_framework("/System/Library/Cocoa.framework/Cocoa", "Cocoa"), "/System/Library/Frameworks/Cocoa.framework/Cocoa")
        self.assertEqual(dyld.dyld_framework("/System/Library/Cocoa.framework/Cocoa", "Cocoa", "A"), "/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa")