示例#1
0
def test_destination_regular_file(tmp_path):
    """If `destination` is a regular file, refuse to write there"""
    path = fixture_path / 'test_content'
    destination = tmp_path / 'file'
    destination.write_text('test')
    with pytest.raises(NotADirectoryError):
        naucse_render.compile(path=path, destination=destination)
示例#2
0
def test_destination_unrelated_directory_rejected(tmp_path):
    """If `destination` has data (and no course.json), refuse to delete it"""
    path = fixture_path / 'test_content'
    destination = tmp_path
    (destination / 'other_file').write_text('test')
    with pytest.raises(ValueError):
        naucse_render.compile(path=path, destination=destination)
示例#3
0
def test_destination_old_directory_overwritten(tmp_path):
    """If `destination` has old `course.json`, it's deleted & overwritten"""
    path = fixture_path / 'test_content'
    destination = tmp_path
    (destination / 'course.json').write_text('test')
    (destination / 'other_file').write_text('test')
    naucse_render.compile(path=path, destination=destination)
    assert (destination / 'course.json').exists()
    assert not (destination / 'other_file').exists()
示例#4
0
def compile(slug, path, destination, edit_repo_url, edit_repo_branch):
    edit_info = {}
    if edit_repo_url:
        edit_info['url'] = edit_repo_url
    if edit_repo_branch:
        edit_info['branch'] = edit_repo_branch
    if slug == '':
        slug = None
    naucse_render.compile(
        slug=slug,
        path=path,
        destination=destination,
        edit_info=edit_info,
    )
示例#5
0
def test_compile_course(tmp_path, edit_info):
    expected = edit_info or None  # we expect nothing from empty dicts
    kwargs = {}
    if edit_info is not None:
        kwargs['edit_info'] = edit_info
    path = fixture_path / 'test_content'
    course_info = naucse_render.compile(path=str(path),
                                        destination=tmp_path,
                                        **kwargs)
    with open(tmp_path / 'course.json') as f:
        data = json.load(f)
    assert data['course'].get('edit_info') == expected
示例#6
0
def test_compile_course(slug, tmp_path):
    path = fixture_path / 'test_content'
    if slug is None:
        args = ()
    else:
        args = (slug, )
    course_info = naucse_render.compile(
        *args,
        path=str(path),
        destination=tmp_path,
    )
    slug = slug or 'default'
    expected_path = fixture_path / 'expected-compiled' / slug
    if expected_path.exists():
        assert_dirs_same(
            tmp_path,
            expected_path,
        )
    else:
        if 'TEST_NAUCSE_DUMP_YAML' in os.environ:
            shutil.copytree(tmp_path, expected_path)
        else:
            raise AssertionError(
                'Expected output missing; set TEST_NAUCSE_DUMP_YAML=1')
示例#7
0
def test_destination_empty_directory_filled(tmp_path):
    """If `destination` is empty, it is filled"""
    path = fixture_path / 'test_content'
    destination = tmp_path
    naucse_render.compile(path=path, destination=destination)
    assert (destination / 'course.json').exists()
示例#8
0
def test_destination_new_directory_created(tmp_path):
    """If `destination` doesn't exist, it is created"""
    path = fixture_path / 'test_content'
    destination = tmp_path / 'new_dir' / 'subdir'
    naucse_render.compile(path=path, destination=destination)
    assert (destination / 'course.json').exists()