<commit_before>import os

from .. import run_python_module
from .base import BaseTestApp


class TestNbGraderFetch(BaseTestApp):

    def _release(self, assignment, exchange):
        self._copy_file("files/test.ipynb", "release/ps1/p1.ipynb")
        run_python_module([
            "nbgrader", "release", assignment,
            "--course", "abc101",
            "--TransferApp.exchange_directory={}".format(exchange)
        ])

    def _fetch(self, assignment, exchange, flags=None, retcode=0):
        cmd = [
            "nbgrader", "fetch", assignment,
            "--course", "abc101",
            "--TransferApp.exchange_directory={}".format(exchange)
        ]

        if flags is not None:
            cmd.extend(flags)

        run_python_module(cmd, retcode=retcode)

    def test_help(self):
        """Does the help display without error?"""
        run_python_module(["nbgrader", "fetch", "--help-all"])

    def test_no_course_id(self, exchange):
        """Does releasing without a course id thrown an error?"""
        self._release("ps1", exchange)
        cmd = [
            "nbgrader", "fetch", "ps1",
            "--TransferApp.exchange_directory={}".format(exchange)
        ]
        run_python_module(cmd, retcode=1)

    def test_fetch(self, exchange):
        self._release("ps1", exchange)
        self._fetch("ps1", exchange)
        assert os.path.isfile("ps1/p1.ipynb")

        # make sure it fails if the assignment already exists
        self._fetch("ps1", exchange, retcode=1)

        # make sure it fails even if the assignment is incomplete
        os.remove("ps1/p1.ipynb")
        self._fetch("ps1", exchange, retcode=1)<commit_msg>Update tests for nbgrader fetch<commit_after>import os
from os.path import join

from .. import run_python_module
from .base import BaseTestApp


class TestNbGraderFetch(BaseTestApp):

    def _release(self, assignment, exchange, course_dir):
        self._copy_file(join("files", "test.ipynb"), join(course_dir, "release", "ps1", "p1.ipynb"))
        run_python_module([
            "nbgrader", "release", assignment,
            "--course", "abc101",
            "--TransferApp.exchange_directory={}".format(exchange)
        ])

    def _fetch(self, assignment, exchange, flags=None, retcode=0):
        cmd = [
            "nbgrader", "fetch", assignment,
            "--course", "abc101",
            "--TransferApp.exchange_directory={}".format(exchange)
        ]

        if flags is not None:
            cmd.extend(flags)

        run_python_module(cmd, retcode=retcode)

    def test_help(self):
        """Does the help display without error?"""
        run_python_module(["nbgrader", "fetch", "--help-all"])

    def test_no_course_id(self, exchange, course_dir):
        """Does releasing without a course id thrown an error?"""
        self._release("ps1", exchange, course_dir)
        cmd = [
            "nbgrader", "fetch", "ps1",
            "--TransferApp.exchange_directory={}".format(exchange)
        ]
        run_python_module(cmd, retcode=1)

    def test_fetch(self, exchange, course_dir):
        self._release("ps1", exchange, course_dir)
        self._fetch("ps1", exchange)
        assert os.path.isfile(join("ps1", "p1.ipynb"))

        # make sure it fails if the assignment already exists
        self._fetch("ps1", exchange, retcode=1)

        # make sure it fails even if the assignment is incomplete
        os.remove(join("ps1", "p1.ipynb"))
        self._fetch("ps1", exchange, retcode=1)
{'fraction_non_alphanumeric': 0.13327625570776255, 'fraction_numerical': 0.012557077625570776, 'mean_word_length': 2.6059670781893005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7577931', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1028, 'n_words': 242}