예제 #1
0
    def test_duplicate_registration_overwrite(self):
        """Test register error for duplicate package"""

        # Register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # Check that global registry was updated
        ensure_live_registry_updated(self.modules)

        # Verify update
        ensure_updated_stored_modules(self.modules)

        # Create a new package, the same as an existing one, but with a
        # different module name
        mod_name = self.module_names[0]
        sys.modules['pysat_error.test_faux_module'] = sys.modules[mod_name]

        # Register packages again
        registry.register(['pysat_error.test_faux_module'], overwrite=True)
        self.modules[0] = ('pysat_error.test_faux_module', 'platname1',
                           'name1')

        # Check that global registry was updated
        ensure_live_registry_updated(self.modules)

        # Verify update
        ensure_updated_stored_modules(self.modules)

        return
예제 #2
0
    def test_module_registration_non_importable(self):
        """Test registering a non-existent module"""

        with pytest.raises(Exception):
            registry.register(['made.up.module'])

        return
예제 #3
0
    def test_duplicate_registration_error(self):
        """Test register error for duplicate package"""

        # Register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # Check that global registry was updated
        ensure_live_registry_updated(self.modules)

        # Verify update
        ensure_updated_stored_modules(self.modules)

        # Create a new package, the same as an existing one but with a
        # different module name
        mod_name = self.module_names[0]
        sys.modules['pysat_error.test_faux_module'] = sys.modules[mod_name]

        # register packages again, this should error
        with pytest.raises(ValueError):
            registry.register(['pysat_error.test_faux_module'])

        return
예제 #4
0
    def test_platform_name_removal_single(self):
        """Test removing single platform/name at a time"""

        # Register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # Verify registration
        ensure_live_registry_updated(self.modules)

        # Verify stored update
        ensure_updated_stored_modules(self.modules)

        # Remove them using platform and name
        all_modules = list(self.modules)
        for i, self.platform in enumerate(self.platforms):
            # Set the name and module for removal
            self.name = self.names[i]
            self.modules = [all_modules[i]]

            # Remove by platform and name, verifying results
            registry.remove([self.platform], [self.name])
            self.ensure_not_in_stored_modules()

            # Ensure other names and platforms are still present
            if i < len(self.platforms) - 1:
                ensure_updated_stored_modules(self.modules[i + 1:])

        return
예제 #5
0
    def test_platform_removal_single(self):
        """Test removing single platform at a time"""

        # Register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # Verify registration
        ensure_live_registry_updated(self.modules)

        # Verify stored update
        ensure_updated_stored_modules(self.modules)

        # Remove modules using only the platform. Doing this one by one ensures
        # more lines are tested  and other registered packages are still
        # present until their removal is performed.
        uplatforms, idx = np.unique(self.platforms, return_index=True)
        umodules = np.asarray(self.modules)[idx]
        for i, self.platform in enumerate(uplatforms):
            # Remove all Instruments on this platform and verify absence
            registry.remove([self.platform], [None])
            self.modules = [umodules[i]]
            self.ensure_not_in_stored_modules()

            # Test that other names still present
            if i < len(self.platforms) - 1:
                ensure_updated_stored_modules(umodules[i + 1:])

        return
예제 #6
0
    def test_platform_name_length_removal_error(self, par_plat, par_name):
        """Test error raised when platforms and names unequal lengths"""

        # Register all modules at once
        registry.register(self.module_names)

        # Raise error when removing non-existent Instruments
        with pytest.raises(ValueError):
            registry.remove(par_plat, par_name)

        return
예제 #7
0
    def test_registration(self):
        """Test registering multiple instruments at once"""

        # Register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # Verify registration
        ensure_live_registry_updated(self.modules)

        # Verify stored update
        ensure_updated_stored_modules(self.modules)

        return
예제 #8
0
    def test_platform_removal(self):
        """Test removing entire platform at once"""

        # register all modules at once
        registry.register(self.module_names)

        # Verify instantiation by by platform/name combo
        for self.module_name, self.platform, self.name in self.modules:
            self.module_name = None  # Must be None to use platform/name combo
            self.verify_inst_instantiation()

        # verify registration
        ensure_live_registry_updated(self.modules)

        # verify stored update
        ensure_updated_stored_modules(self.modules)

        # remove them using only platform
        uplatforms = np.unique(self.platforms)
        registry.remove(uplatforms, [None] * len(uplatforms))

        return