Exemplo n.º 1
0
    def test_read(self, create_db_instance):
        """Test read is coherent from view and wrapped database."""
        database = create_db_instance
        readonly_database = ReadOnlyDB(database)

        args = {"collection_name": "trials", "query": {"experiment": "supernaedo2"}}
        readonly_result = readonly_database.read(**args)
        result = database.read(**args)

        assert len(result) > 0  # Otherwise the test is pointless
        assert readonly_result == result
Exemplo n.º 2
0
    def test_read(self, hacked_exp):
        """Test read is coherent from view and wrapped database."""
        database = get_storage()._db
        readonly_database = ReadOnlyDB(database)

        args = {
            "collection_name": "experiments",
            "query": {
                "name": "supernaedo2-dendi"
            },
        }
        readonly_result = readonly_database.read(**args)
        result = database.read(**args)

        assert len(result) > 0  # Otherwise the test is pointless
        assert readonly_result == result
Exemplo n.º 3
0
    def test_valid_attributes(self, storage):
        """Test attributes are coherent from view and wrapped database."""
        database = storage._db
        readonly_database = ReadOnlyDB(database)

        assert readonly_database.host == database.host
        assert readonly_database.port == database.port
Exemplo n.º 4
0
    def test_valid_attributes(self, create_db_instance):
        """Test attributes are coherent from view and wrapped database."""
        database = create_db_instance
        readonly_database = ReadOnlyDB(database)

        assert readonly_database.is_connected == database.is_connected
        assert readonly_database.host == database.host
        assert readonly_database.port == database.port
        assert readonly_database.username == database.username
        assert readonly_database.password == database.password
Exemplo n.º 5
0
    def test_invalid_attributes(self, storage):
        """Test that attributes for writing are not accessible."""
        database = storage._db
        readonly_database = ReadOnlyDB(database)

        # Test that database.ensure_index indeed exists
        database.ensure_index
        with pytest.raises(AttributeError):
            readonly_database.ensure_index

        # Test that database.write indeed exists
        database.write
        with pytest.raises(AttributeError):
            readonly_database.write

        # Test that database.read_and_write indeed exists
        database.read_and_write
        with pytest.raises(AttributeError):
            readonly_database.read_and_write

        # Test that database.remove indeed exists
        database.remove
        with pytest.raises(AttributeError):
            readonly_database.remove
Exemplo n.º 6
0
    def __init__(self, name):
        """Initialize viewed experiment object with primary key (:attr:`name`, :attr:`user`).

        Build an experiment from configuration found in `Database` with a key (name, user).

        .. note::

            A view is fully configured at initialiation. It cannot be reconfigured.
            If no experiment is found for the key (name, user), a `ValueError` will be raised.

        :param name: Describe a configuration with a unique identifier per :attr:`user`.
        :type name: str
        """
        self._experiment = Experiment(name)

        if self._experiment.id is None:
            raise ValueError(
                "No experiment with given name '%s' for user '%s' inside database, "
                "no view can be created." %
                (self._experiment.name, self._experiment.metadata['user']))

        try:
            self._experiment.configure(self._experiment.configuration,
                                       enable_branching=False)
        except ValueError as e:
            if "Configuration is different and generate a branching event" in str(
                    e):
                raise RuntimeError(
                    "Configuration in the database does not correspond to the one generated by "
                    "Experiment object. This is likely due to a backward incompatible update in "
                    "Oríon. Please repport to https://github.com/mila-udem/orion/issues."
                ) from e

            raise

        self._experiment._db = ReadOnlyDB(self._experiment._db)