コード例 #1
0
ファイル: test_teacher.py プロジェクト: Sidiox/CodeGra.fs
def test_make_directories(mount_dir, sub_done, sub_open):
    with pytest.raises(FileExistsError):
        mkdir(sub_open, 'dir')
    assert isdir(sub_open, 'dir')

    with pytest.raises(PermissionError):
        rm_rf(sub_open, 'dir')

    assert isdir(sub_open, 'dir')
    assert isfile(sub_open, 'dir', 'single_file_work')
    assert isfile(sub_open, 'dir', 'single_file_work_copy')

    with pytest.raises(IsADirectoryError):
        rm(sub_done, 'dir')
    with pytest.raises(OSError):
        rmdir(sub_done, 'dir')
    assert isdir(sub_done, 'dir')

    rm_rf(sub_done, 'dir')

    assert 'dir' not in ls(sub_done)

    mkdir(sub_done, 'dir')
    assert isdir(sub_done, 'dir')

    rmdir(sub_done, 'dir')
    assert 'dir' not in ls(sub_done)
コード例 #2
0
def test_courses_with_slash(mount, admin_jwt, mount_dir):
    n_id = uuid.uuid4().hex
    course_name = 'New/Course_{}'.format(n_id)
    result_course_name = 'New-Course_{}'.format(n_id)
    print(n_id)

    requests.patch(
        'http://localhost:5000/api/v1/roles/4',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'value': True,
            'permission': 'can_create_courses'
        }
    ).raise_for_status()

    requests.post(
        'http://localhost:5000/api/v1/courses/',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'name': course_name
        }
    ).raise_for_status()

    time.sleep(1)

    mount()
    assert result_course_name in ls(mount_dir)

    mount(ascii_only=True)
    assert result_course_name in ls(mount_dir)
コード例 #3
0
def test_delete_invalid_file(mount_dir):
    with pytest.raises(PermissionError):
        top = [l for l in ls(mount_dir) if isdir(mount_dir, l)][0]
        rm_rf(mount_dir, top)

    with pytest.raises(PermissionError):
        top = [l for l in ls(mount_dir) if isdir(mount_dir, l)][0]
        f = [l for l in ls(mount_dir, top) if isdir(mount_dir, top, l)][0]
        rm_rf(mount_dir, top, f)
コード例 #4
0
ファイル: test_teacher.py プロジェクト: Sidiox/CodeGra.fs
def test_list_submissions(mount_dir):
    for course in ['Besturingssystemen', 'Programmeertalen']:
        for assig in ls(mount_dir, course):
            for sub in ls(mount_dir, course, assig):
                assert any(
                    'Student{i}'.format(i=i) in sub
                    for i in range(1, 5)) or 'Œlµo' in sub or sub[0] == '.'

    for assig in ls(mount_dir, 'Project Software Engineering'):
        for sub in ls(mount_dir, 'Project Software Engineering', assig):
            assert 'Thomas Schaper' in sub or sub[0] == '.'
コード例 #5
0
def test_courses_non_ascii(mount, admin_jwt, mount_dir):
    n_id = str(uuid.uuid4())
    course_name1 = 'ASCII_New_Course-{}-*'.format(n_id)
    course_name2 = 'ASCII_New_Course-{}-:'.format(n_id)
    res_course_name = 'ASCII_New_Course-{}'.format(n_id)
    print(n_id)

    requests.patch(
        'http://localhost:5000/api/v1/roles/4',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'value': True,
            'permission': 'can_create_courses'
        }
    ).raise_for_status()

    requests.post(
        'http://localhost:5000/api/v1/courses/',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'name': course_name1
        }
    ).raise_for_status()

    time.sleep(1)

    requests.post(
        'http://localhost:5000/api/v1/courses/',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'name': course_name2
        }
    ).raise_for_status()

    mount()

    assert course_name1 in ls(mount_dir)
    assert course_name2 in ls(mount_dir)

    mount(ascii_only=True)

    assert len(
        [l for l in ls(mount_dir) if l.startswith(res_course_name)]
    ) == 2
コード例 #6
0
def test_list_submissions(mount_dir, mount):
    course_dir = join(mount_dir, 'Programmeertalen')
    assert isdir(mount_dir)
    assert isdir(course_dir)

    for assig in ls(course_dir):
        for sub in ls(course_dir, assig):
            assert 'Student1' in sub or sub[0] == '.'

    mount(assigned_to_me=True)

    for assig in ls(course_dir):
        for sub in ls(course_dir, assig):
            assert 'Student1' in sub or sub[0] == '.'
コード例 #7
0
def test_non_exising_submission(assig_done):
    with pytest.raises(FileNotFoundError):
        open(join(assig_done, 'NON EXISTING', 'file'), 'x').close()

    with pytest.raises(FileNotFoundError):
        mkdir(assig_done, 'NON EXISTING', 'file')

    with pytest.raises(FileNotFoundError):
        rename(
            [assig_done, 'NON EXISTING', 'file'],
            [assig_done, 'NON EXISTING', 'file2']
        )

    with pytest.raises(FileNotFoundError):
        ls(assig_done, 'NON EXISTING')
コード例 #8
0
def test_write_to_directory(sub_done):
    fdir = join(sub_done, 'new_dir')
    fname = join(fdir, 'new_file')

    mkdir(fdir)
    assert isdir(fdir)
    assert not isfile(fdir)

    with pytest.raises(IsADirectoryError):
        with open(fdir, 'w') as f:
            f.write('hello\n')

    open(fname, 'w').close()
    with pytest.raises(NotADirectoryError):
        ls(fname)
    with pytest.raises(FileExistsError):
        mkdir(fname)
コード例 #9
0
def test_latest_only(assig_done, latest_only):
    amount = 0
    for item in ls(assig_done):
        amount += 1 if 'Student1' in item else 0
    if latest_only:
        assert amount == 1
    else:
        assert amount > 1
コード例 #10
0
def test_difficult_assigned_to(
    mount, teacher_jwt, student_jwt, teacher_id, ta_id, assig_open,
    student2_jwt
):
    assig_id = open(join(assig_open, '.cg-assignment-id')).read().strip()

    def submit(jwt):
        req = requests.post(
            'http://localhost:5000/api/v1/assignments/{}/submission'.
            format(assig_id),
            headers={'Authorization': 'Bearer ' + jwt},
            files=dict(
                file=open('./test_data/multiple_dir_archive.zip', 'rb')
            )
        )

        req.raise_for_status()
        return req.json()

    def assign(sub, user_id):
        requests.patch(
            'http://localhost:5000/api/v1/submissions/{}/grader'.format(
                sub["id"]
            ),
            json={
                'user_id': user_id
            },
            headers={
                'Authorization': 'Bearer ' + teacher_jwt
            },
        ).raise_for_status

    sub2 = submit(student2_jwt)
    old = submit(student_jwt)
    new = submit(student_jwt)
    print(sub2, old, new)

    assign(sub2, ta_id)
    assign(old, ta_id)
    assign(new, teacher_id)

    mount(assigned_to_me=True)
    # We do not expect to see any submission. A submission is assigned to us,
    # but it is not the newest of the student, so we do not show it.
    print(ls(assig_open))
    assert not any(['Student1' in l for l in ls(assig_open)])
    assert any(['Student2' in l for l in ls(assig_open)])
    mount(assigned_to_me=False)
    assert ls(assig_open)

    # Now we assign the newest submission to us, so we expect to see it.
    requests.patch(
        'http://localhost:5000/api/v1/submissions/{}/grader'.format(new["id"]),
        json={'user_id': ta_id},
        headers={'Authorization': 'Bearer ' + teacher_jwt},
    )
    mount(assigned_to_me=True)
    print(ls(assig_open))
    assert any(['Student1' in l for l in ls(assig_open)])
    assert any(['Student2' in l for l in ls(assig_open)])
コード例 #11
0
ファイル: test_teacher.py プロジェクト: Sidiox/CodeGra.fs
def test_list_courses(mount_dir):
    assert isdir(mount_dir)
    for course in [
            'Besturingssystemen', 'Programmeertalen',
            'Project Software Engineering'
    ]:
        assert isdir(mount_dir, course)

    assert set(ls(mount_dir)) == set([
        'Besturingssystemen', 'Programmeertalen',
        'Project Software Engineering', '.api.socket', '.cg-mode'
    ])
コード例 #12
0
def test_create_file_outside_submissions(mount_dir, mount):
    with open(join(mount_dir, 'file'), 'w+') as f:
        f.write('hello\n')
    with open(join(mount_dir, 'file'), 'r') as f:
        assert f.read() == 'hello\n'

    with open(
        join(
            mount_dir, [l for l in ls(mount_dir) if isdir(mount_dir, l)][0],
            'file'
        ), 'w+'
    ) as f:
        f.write('hello\n')

    mkdir(mount_dir, 'dir')
    mkdir(mount_dir, 'dir', 'hello')
    mkdir(mount_dir, 'dir', 'hello', 'codegrade')
    with open(
        join(mount_dir, 'dir', 'hello', 'codegrade', 'nice_to_meet'), 'w'
    ) as f:
        f.write('hello')
    with pytest.raises(FileExistsError):
        mkdir(mount_dir, 'dir', 'hello', 'codegrade', 'nice_to_meet')
    with open(
        join(mount_dir, 'dir', 'hello', 'codegrade', 'nice_to_meet'), 'r'
    ) as f:
        assert f.read() == 'hello'

    with pytest.raises(FileNotFoundError):
        with open(join(mount_dir, 'dir', 'bye', 'cg'), 'w') as f:
            pass
    with pytest.raises(FileNotFoundError):
        mkdir(mount_dir, 'dir', 'bye', 'cg2')

    assert 'dir' in ls(mount_dir)
    assert 'file' in ls(mount_dir)
    mount()
    assert 'dir' not in ls(mount_dir)
    assert 'file' not in ls(mount_dir)
コード例 #13
0
def test_create_invalid_file(mount_dir):
    with pytest.raises(PermissionError):
        with open(join(mount_dir, 'file'), 'w+') as f:
            f.write('hello\n')

    with pytest.raises(PermissionError):
        with open(
            join(
                mount_dir, [l for l in ls(mount_dir)
                            if isdir(mount_dir, l)][0], 'file'
            ), 'w+'
        ) as f:
            f.write('hello\n')
コード例 #14
0
ファイル: test_teacher.py プロジェクト: Sidiox/CodeGra.fs
def test_list_assigned_submissions(mount, mount_dir, teacher_jwt, teacher_id):
    course = 'Programmeertalen'

    for assig in ls(mount_dir, course):
        for sub in ls(mount_dir, course, assig):
            if 'Student1' in sub:
                with open(
                        join(mount_dir, course, assig, sub,
                             '.cg-submission-id')) as f:
                    sub_id = f.read().strip()
                r = requests.patch(
                    f'http://localhost:5000/api/v1/submissions/{sub_id}/grader',
                    json={'user_id': teacher_id},
                    headers={
                        'Authorization': 'Bearer ' + teacher_jwt,
                    })
                assert r.status_code == 204

    mount(assigned_to_me=True)

    for assig in ls(mount_dir, course):
        for sub in ls(mount_dir, course, assig):
            assert 'Student1' in sub or sub[0] == '.'
コード例 #15
0
def test_list_courses(mount_dir):
    assert isdir(mount_dir)
    for course in [
            'Besturingssystemen', 'Programmeertalen',
            'Project Software Engineering'
    ]:
        assert isdir(mount_dir, course)

    ls_res = [
        x for x in ls(mount_dir)
        if not x.startswith('ASCII_') and not x.startswith('New_Assig-')
    ]
    assert set(ls_res) == set([
        'Besturingssystemen', 'Programmeertalen',
        'Project Software Engineering', '.api.socket', '.cg-mode'
    ])
コード例 #16
0
    def get_file_list(path_root, seqs, exts=None):
        """ Gets the list of paths to files contained in dirs listed in `seqs`.
        The paths are relative w.r.t. the `path_root`.

        Args:
            path_root (str): Path to root dir containing sequences (directories)
                of data samples.
            seqs (lsit of str): Names of sequences (dirs) to load.
            exts (list of str): Supported file name extensions.

        Returns:
            list of str: List of paths to files.
        """
        return [
            hlp.jn(s, f) for s in seqs
            for f in hlp.ls(hlp.jn(path_root, s), exts=exts)
        ]
コード例 #17
0
def test_double_assignment(mount, teacher_jwt, assig_open):
    n_id = str(uuid.uuid4())
    assig_name = 'New_Assig-{}'.format(n_id)
    print(n_id)
    assig_id = open(join(assig_open, '.cg-assignment-id')).read().strip()
    course_id = requests.get(
        'http://localhost:5000/api/v1/assignments/{}'.format(assig_id),
        headers={
            'Authorization': 'Bearer ' + teacher_jwt
        },
    ).json()['course']['id']

    assert requests.post(
        'http://localhost:5000/api/v1/courses/{}/assignments/'.
        format(course_id),
        headers={
            'Authorization': 'Bearer ' + teacher_jwt
        },
        json={
            'name': assig_name
        }
    ).status_code < 300
    # Make sure we have some time between the assignments
    time.sleep(1)
    assert requests.post(
        'http://localhost:5000/api/v1/courses/{}/assignments/'.
        format(course_id),
        headers={
            'Authorization': 'Bearer ' + teacher_jwt
        },
        json={
            'name': assig_name
        }
    ).status_code < 300

    mount()

    assert len(
        [l for l in ls(assig_open, '..') if l.startswith(assig_name)]
    ) == 2
コード例 #18
0
def test_double_course(mount, admin_jwt, mount_dir):
    n_id = str(uuid.uuid4())
    course_name = 'New_Assig-{}'.format(n_id)
    print(n_id)

    assert requests.patch(
        'http://localhost:5000/api/v1/roles/4',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'value': True,
            'permission': 'can_create_courses'
        }
    ).status_code < 300

    assert requests.post(
        'http://localhost:5000/api/v1/courses/',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'name': course_name
        }
    ).status_code < 300
    time.sleep(1)
    assert requests.post(
        'http://localhost:5000/api/v1/courses/',
        headers={
            'Authorization': 'Bearer ' + admin_jwt
        },
        json={
            'name': course_name
        }
    ).status_code < 300

    mount()

    assert len([l for l in ls(mount_dir) if l.startswith(course_name)]) == 2
def process_sequence(obj):
    # Get list of paths in obj. category in AtlasNet.
    pth_files_an = jn(pth_root_an, obj, 'ply')
    files = ls(pth_files_an, exts='txt')

    # Peocess files.
    for f in files:
        # Extract file name.
        fn_base = f.split('.')[0]

        # Load .obj mesh from ShapeNet.
        pth_f_sn = jn(
            pth_root_sn, obj, fn_base, 'models', 'model_normalized.obj')
        assert os.path.exists(pth_f_sn)
        verts, faces = load_obj(pth_f_sn)

        # Load tf and apply.
        pth_f_an = jn(pth_files_an, f)
        T, s = load_tf(pth_f_an)
        verts = (verts - T) / s

        # Compute area.
        area = mesh_area(verts, faces)

        # Write area to the file.
        with open(pth_f_an, 'r') as fobj:
            txt = fobj.read()
            assert len(txt.splitlines()) == 2
            has_nl = txt.endswith('\n')

        with open(pth_f_an, 'a') as fobj:
            fobj.write('{}{:.6f}'.format(('\n', '')[has_nl], area))

        with num_samples_done.get_lock():
            num_samples_done.value += 1

    with finished_seqs.get_lock():
        finished_seqs.value += 1
def get_total_num_samples():
    num_total = 0
    seqs = lsd(pth_root_an)
    for s in seqs:
        num_total += len(ls(jn(pth_root_an, s), exts='txt'))
    return num_total
コード例 #21
0
ファイル: test_teacher.py プロジェクト: Sidiox/CodeGra.fs
def test_read_directories(mount_dir, sub_done, sub_open):
    for sub in [sub_done, sub_open]:
        assert 'dir' in ls(sub)
        assert 'dir2' in ls(sub)
        assert 'dir1' not in ls(sub)

        assert 'single_file_work' in ls(sub, 'dir')
        assert 'single_file_work_copy' in ls(sub, 'dir')
        assert 'single_file_work_copy2' not in ls(sub, 'dir')

        assert 'single_file_work' in ls(sub, 'dir2')
        assert 'single_file_work_copy' in ls(sub, 'dir2')
        assert 'single_file_work_copy2' not in ls(sub, 'dir2')

        with pytest.raises(FileNotFoundError):
            ls(sub, 'dir3')