Ejemplo n.º 1
0
    def test_delete(self):
        # check project is not initialized if wrong home
        Config().set_home(os.path.join("does", "not", "exist"))
        failed = False
        try:
            delete()
        except InvalidProjectPath:
            failed = True
        assert failed

        # check for snapshot id that does not exist
        Config().set_home(self.temp_dir)
        failed = False
        try:
            delete(snapshot_id="does_not_exist")
        except EntityNotFound:
            failed = True
        assert failed

        # delete a snapshot
        test_filepath = os.path.join(self.temp_dir, "script.py")
        with open(test_filepath, "wb") as f:
            f.write(to_bytes("import numpy\n"))
            f.write(to_bytes("import sklearn\n"))

        snapshot_obj = create(message="delete_test")

        snapshot_list_before_delete = ls(filter='delete_test')

        delete(snapshot_id=snapshot_obj.id)

        snapshot_list_after_delete = ls(filter='delete_test')

        assert len(snapshot_list_before_delete) == 1
        assert len(snapshot_list_after_delete) == 0
Ejemplo n.º 2
0
    def test_ls(self):
        # check project is not initialized if wrong home
        Config().set_home(os.path.join("does", "not", "exist"))
        failed = False
        try:
            ls()
        except InvalidProjectPath:
            failed = True
        assert failed

        # check session does not exist if wrong session
        Config().set_home(self.temp_dir)
        failed = False
        try:
            ls(session_id="does_not_exist")
        except SessionDoesNotExist:
            failed = True
        assert failed

        # create with default params and files to commit
        test_filepath = os.path.join(self.temp_dir, "script.py")
        with open(test_filepath, "wb") as f:
            f.write(to_bytes("import numpy\n"))
            f.write(to_bytes("import sklearn\n"))

        create(message="test1")

        # list all snapshots with no filters
        snapshot_list_1 = ls()

        assert snapshot_list_1
        assert len(list(snapshot_list_1)) == 1
        assert isinstance(snapshot_list_1[0], Snapshot)

        # Create a snapshot with default params, files, and environment
        test_filepath = os.path.join(self.temp_dir, "Dockerfile")
        with open(test_filepath, "wb") as f:
            f.write(to_bytes("FROM python:3.5-alpine"))
        create(message="test2")

        # list all snapshots with no filters (works when more than 1 snapshot)
        snapshot_list_2 = ls()

        assert snapshot_list_2
        assert len(list(snapshot_list_2)) == 2
        assert isinstance(snapshot_list_2[0], Snapshot)
        assert isinstance(snapshot_list_2[1], Snapshot)

        # list snapshots with specific filter
        snapshot_list_3 = ls(filter="test2")

        assert snapshot_list_3
        assert len(list(snapshot_list_3)) == 1
        assert isinstance(snapshot_list_3[0], Snapshot)

        # list snapshots with filter of none
        snapshot_list_4 = ls(filter="test3")

        assert len(list(snapshot_list_4)) == 0