当前位置: 首页>>代码示例>>Python>>正文


Python Gradebook.add_assignment方法代码示例

本文整理汇总了Python中nbgrader.api.Gradebook.add_assignment方法的典型用法代码示例。如果您正苦于以下问题:Python Gradebook.add_assignment方法的具体用法?Python Gradebook.add_assignment怎么用?Python Gradebook.add_assignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nbgrader.api.Gradebook的用法示例。


在下文中一共展示了Gradebook.add_assignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _setup_db

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
 def _setup_db(self):
     dbpath = self._init_db()
     gb = Gradebook(dbpath)
     gb.add_assignment("ps1", duedate="2015-02-02 14:58:23.948203 PST")
     gb.add_student("foo")
     gb.add_student("bar")
     return dbpath
开发者ID:redSlug,项目名称:nbgrader,代码行数:9,代码来源:test_nbgrader_autograde.py

示例2: gradebook

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
def gradebook(request, tempdir):
    # create a "class files" directory
    origdir = os.getcwd()
    os.mkdir("class_files")
    os.chdir("class_files")

    # copy files from the user guide
    source_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "source", "user_guide", "source")
    submitted_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "source", "user_guide", "submitted")

    shutil.copytree(os.path.join(os.path.dirname(__file__), source_path), "source")
    shutil.copytree(os.path.join(os.path.dirname(__file__), submitted_path), "submitted")

    # create the gradebook
    gb = Gradebook("sqlite:///gradebook.db")
    gb.add_assignment("Problem Set 1")
    gb.add_student("Bitdiddle", first_name="Ben", last_name="B")
    gb.add_student("Hacker", first_name="Alyssa", last_name="H")
    gb.add_student("Reasoner", first_name="Louis", last_name="R")

    # run nbgrader assign
    run_command([
        "nbgrader", "assign", "Problem Set 1",
        "--IncludeHeaderFooter.header=source/header.ipynb"
    ])

    # run the autograder
    run_command(["nbgrader", "autograde", "Problem Set 1"])

    def fin():
        os.chdir(origdir)
        shutil.rmtree("class_files")
    request.addfinalizer(fin)

    return gb
开发者ID:MatKallada,项目名称:nbgrader,代码行数:37,代码来源:conftest.py

示例3: test_save_cells

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_save_cells(self, db):
        """Ensure cells are saved into the database"""
        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")

        gb = Gradebook(db)
        gb.add_assignment("ps1")

        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        notebook = gb.find_notebook("test", "ps1")
        assert len(notebook.grade_cells) == 8
开发者ID:haraldschilly,项目名称:nbgrader,代码行数:13,代码来源:test_nbgrader_assign.py

示例4: test_save_cells

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_save_cells(self):
        """Ensure cells are saved into the database"""
        with self._temp_cwd(["files/test.ipynb"]):
            os.makedirs('source/ps1')
            shutil.move("test.ipynb", "source/ps1/test.ipynb")

            dbpath = self._init_db()
            gb = Gradebook(dbpath)
            gb.add_assignment("ps1")

            self._run_command('nbgrader assign ps1 --db="{}"'.format(dbpath))

            notebook = gb.find_notebook("test", "ps1")
            assert_equal(len(notebook.grade_cells), 8)
开发者ID:redSlug,项目名称:nbgrader,代码行数:16,代码来源:test_nbgrader_assign.py

示例5: init_assignment

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def init_assignment(self, assignment_id, student_id):
        super(AssignApp, self).init_assignment(assignment_id, student_id)

        # try to get the assignment from the database, and throw an error if it
        # doesn't exist
        gb = Gradebook(self.db_url)
        try:
            gb.find_assignment(assignment_id)
        except MissingEntry:
            if self.create_assignment:
                self.log.warning("Creating assignment '%s'", assignment_id)
                gb.add_assignment(assignment_id)
            else:
                self.fail("No assignment called '%s' exists in the database", assignment_id)
开发者ID:haraldschilly,项目名称:nbgrader,代码行数:16,代码来源:assignapp.py

示例6: test_add_remove_extra_notebooks

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_add_remove_extra_notebooks(self, db):
        """Are extra notebooks added and removed?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        notebook1 = gb.find_notebook("test", "ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command('nbgrader assign ps1 --db="{}" --force'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 2
        gb.db.refresh(notebook1)
        notebook2 = gb.find_notebook("test2", "ps1")

        os.remove("source/ps1/test2.ipynb")
        run_command('nbgrader assign ps1 --db="{}" --force'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        gb.db.refresh(notebook1)
        with pytest.raises(InvalidRequestError):
            gb.db.refresh(notebook2)
开发者ID:svurens,项目名称:nbgrader,代码行数:30,代码来源:test_nbgrader_assign.py

示例7: class_files

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
def class_files(request, tempdir):
    # copy files from the user guide
    source_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "docs", "source", "user_guide", "source")
    shutil.copytree(os.path.join(os.path.dirname(__file__), source_path), "source")

    # create a fake ps1
    os.mkdir(os.path.join("source", "ps1"))
    with open(os.path.join("source", "ps1", "problem 1.ipynb"), "w") as fh:
        write_nb(new_notebook(), fh, 4)

    # create the gradebook
    gb = Gradebook("sqlite:///gradebook.db")
    gb.add_assignment("Problem Set 1")
    gb.add_assignment("ps1")
    gb.add_student("Bitdiddle", first_name="Ben", last_name="B")
    gb.add_student("Hacker", first_name="Alyssa", last_name="H")
    gb.add_student("Reasoner", first_name="Louis", last_name="R")

    return tempdir
开发者ID:vanceeasleaf,项目名称:nbgrader,代码行数:21,代码来源:conftest.py

示例8: init_assignment

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def init_assignment(self, assignment_id, student_id):
        super(AssignApp, self).init_assignment(assignment_id, student_id)

        # try to get the assignment from the database, and throw an error if it
        # doesn't exist
        gb = Gradebook(self.db_url)
        try:
            gb.find_assignment(assignment_id)
        except MissingEntry:
            if self.create_assignment:
                self.log.warning("Creating assignment '%s'", assignment_id)
                gb.add_assignment(assignment_id)
            else:
                self.fail("No assignment called '%s' exists in the database", assignment_id)
        else:
            # check if there are any extra notebooks in the db that are no longer
            # part of the assignment, and if so, remove them
            if self.notebook_id == "*":
                self._clean_old_notebooks(assignment_id, student_id)
开发者ID:c0ns0le,项目名称:nbgrader,代码行数:21,代码来源:assignapp.py

示例9: test_add_extra_notebooks_with_submissions

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_add_extra_notebooks_with_submissions(self, db):
        """Is an error thrown when new notebooks are added and there are existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1

        gb.add_student("hacker123")
        gb.add_submission("ps1", "hacker123")

        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command('nbgrader assign ps1 --db="{}" --force'.format(db), retcode=1)
开发者ID:svurens,项目名称:nbgrader,代码行数:18,代码来源:test_nbgrader_assign.py

示例10: test_remove_extra_notebooks_with_submissions

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_remove_extra_notebooks_with_submissions(self, db):
        """Is an error thrown when notebooks are removed and there are existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        self._copy_file("files/test.ipynb", "source/ps1/test2.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db])

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 2

        gb.add_student("hacker123")
        gb.add_submission("ps1", "hacker123")

        os.remove("source/ps1/test2.ipynb")
        run_command(["nbgrader", "assign", "ps1", "--db", db, "--force"], retcode=1)
开发者ID:MatKallada,项目名称:nbgrader,代码行数:19,代码来源:test_nbgrader_assign.py

示例11: test_same_notebooks_with_submissions

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
    def test_same_notebooks_with_submissions(self, db):
        """Is it ok to run nbgrader assign with the same notebooks and existing submissions?"""
        gb = Gradebook(db)
        assignment = gb.add_assignment("ps1")

        self._copy_file("files/test.ipynb", "source/ps1/test.ipynb")
        run_command('nbgrader assign ps1 --db="{}"'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        notebook = assignment.notebooks[0]

        gb.add_student("hacker123")
        submission = gb.add_submission("ps1", "hacker123")
        submission_notebook = submission.notebooks[0]

        run_command('nbgrader assign ps1 --db="{}" --force'.format(db))

        gb.db.refresh(assignment)
        assert len(assignment.notebooks) == 1
        gb.db.refresh(notebook)
        gb.db.refresh(submission)
        gb.db.refresh(submission_notebook)
开发者ID:svurens,项目名称:nbgrader,代码行数:25,代码来源:test_nbgrader_assign.py

示例12: gradebook

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
def gradebook(db):
    gb = Gradebook(db)
    gb.add_assignment("ps0")
    return gb
开发者ID:c0ns0le,项目名称:nbgrader,代码行数:6,代码来源:test_savecells.py

示例13: TestSaveCells

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
class TestSaveCells(TestBase):

    def setup(self):
        super(TestSaveCells, self).setup()
        db_url = self._init_db()
        self.gb = Gradebook(db_url)
        self.gb.add_assignment("ps0")

        self.preprocessor = SaveCells()
        self.resources = {
            "nbgrader": {
                "db_url": db_url,
                "assignment": "ps0",
                "notebook": "test"
            }
        }

    def test_save_code_grade_cell(self):
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert_equal(grade_cell.max_score, 1, "max_score is incorrect")
        assert_equal(grade_cell.source, "hello", "source is incorrect")
        assert_equal(grade_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(grade_cell.cell_type, "code", "cell_type is incorrect")

    def test_save_markdown_grade_cell(self):
        cell = self._create_grade_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert_equal(grade_cell.max_score, 1, "max_score is incorrect")
        assert_equal(grade_cell.source, "hello", "source is incorrect")
        assert_equal(grade_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(grade_cell.cell_type, "markdown", "cell_type is incorrect")

    def test_save_code_solution_cell(self):
        cell = self._create_solution_cell("hello", "code")
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        solution_cell = gb.find_solution_cell(0, "test", "ps0")
        assert_equal(solution_cell.source, "hello", "source is incorrect")
        assert_equal(solution_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(solution_cell.cell_type, "code", "cell_type is incorrect")

    def test_save_markdown_solution_cell(self):
        cell = self._create_solution_cell("hello", "markdown")
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        solution_cell = gb.find_solution_cell(0, "test", "ps0")
        assert_equal(solution_cell.source, "hello", "source is incorrect")
        assert_equal(solution_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(solution_cell.cell_type, "markdown", "cell_type is incorrect")

    def test_save_code_grade_and_solution_cell(self):
        cell = self._create_grade_and_solution_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert_equal(grade_cell.max_score, 1, "max_score is incorrect")
        assert_equal(grade_cell.source, "hello", "source is incorrect")
        assert_equal(grade_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(grade_cell.cell_type, "code", "cell_type is incorrect")

        solution_cell = gb.find_solution_cell(0, "test", "ps0")
        assert_equal(solution_cell.source, "hello", "source is incorrect")
        assert_equal(solution_cell.checksum, cell.metadata.nbgrader["checksum"], "checksum is incorrect")
        assert_equal(solution_cell.cell_type, "code", "cell_type is incorrect")

    def test_save_markdown_grade_and_solution_cell(self):
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)

        nb, resources = self.preprocessor.preprocess(nb, self.resources)

        gb = self.preprocessor.gradebook
        grade_cell = gb.find_grade_cell("foo", "test", "ps0")
        assert_equal(grade_cell.max_score, 1, "max_score is incorrect")
#.........这里部分代码省略.........
开发者ID:redSlug,项目名称:nbgrader,代码行数:103,代码来源:test_savecells.py

示例14: TestSaveAutoGrades

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
class TestSaveAutoGrades(TestBase):

    def setup(self):
        super(TestSaveAutoGrades, self).setup()
        db_url = self._init_db()
        self.gb = Gradebook(db_url)
        self.gb.add_assignment("ps0")
        self.gb.add_student("bar")

        self.preprocessor1 = SaveCells()
        self.preprocessor2 = SaveAutoGrades()
        self.resources = {
            "nbgrader": {
                "db_url": db_url,
                "assignment": "ps0",
                "notebook": "test",
                "student": "bar"
            }
        }

    def test_grade_correct_code(self):
        """Is a passing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 1)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 1)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_incorrect_code(self):
        """Is a failing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_unchanged_markdown(self):
        """Is an unchanged markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_changed_markdown(self):
        """Is a changed markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        cell.source = "hello!"
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, None)
        assert_equal(grade_cell.manual_score, None)
        assert grade_cell.needs_manual_grade

    def test_comment_unchanged_code(self):
        """Is an unchanged code cell given the correct comment?"""
        cell = self._create_solution_cell("hello", "code")
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, "No response.")

    def test_comment_changed_code(self):
        """Is a changed code cell given the correct comment?"""
#.........这里部分代码省略.........
开发者ID:redSlug,项目名称:nbgrader,代码行数:103,代码来源:test_saveautogrades.py

示例15: gradebook

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import add_assignment [as 别名]
def gradebook(db):
    gb = Gradebook(db)
    gb.add_assignment("ps1", duedate="2015-02-02 14:58:23.948203 PST")
    gb.add_student("foo")
    gb.add_student("bar")
    return db
开发者ID:c0ns0le,项目名称:nbgrader,代码行数:8,代码来源:conftest.py


注:本文中的nbgrader.api.Gradebook.add_assignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。