Skip to content

Commit

Permalink
Add support to get authors, date/time created, and date/time modified…
Browse files Browse the repository at this point in the history
… for articles (#65)

* Add support to get authors, date/time created, and date/time modified for articles

* Refactor common docs operations to separate function

* Only count required files

* Remove import/export stuff
  • Loading branch information
rzuckerm authored Jul 5, 2023
1 parent 8eeb8b5 commit 713ebce
Show file tree
Hide file tree
Showing 8 changed files with 538 additions and 93 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Changelog
Below you'll find all the changes that have been made to the code with
newest changes first.

0.17.x
------

* v0.17.0
* Added ability to get authors, date/time created, date/time modified for
language, sample program, and project articles.

0.16.x
------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description = fh.read()

MAJOR = 0
MINOR = 16
MINOR = 17
PATCH = 0

name = "subete"
Expand Down
445 changes: 356 additions & 89 deletions subete/repo.py

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def test_image_type(language, expected_result, test_repo):
assert program.image_type() == expected_result


def test_doc_authors(test_repo):
program: subete.SampleProgram = test_repo["Yoix"]["Hello World"]
assert "rzuckerm" in program.doc_authors()


def test_doc_created(test_repo):
program: subete.SampleProgram = test_repo["Yoix"]["Hello World"]
assert program.doc_created() is not None


def test_doc_modified(test_repo):
program: subete.SampleProgram = test_repo["Yoix"]["Hello World"]
assert program.doc_modified() is not None


def test_project_path(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.project_path().endswith("/archive/p/python/hello_world.py")
Expand Down Expand Up @@ -129,10 +144,18 @@ def test_random_program(test_repo):
assert test_repo.random_program() != test_repo.random_program()


def test_approved_projects(test_repo):
assert len(test_repo.approved_projects()) > 0


def test_total_approved_projects(test_repo):
assert test_repo.total_approved_projects() > 0


def test_sorted_language_letters(test_repo):
assert "p" in test_repo.sorted_language_letters()


def test_program_has_docs(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.has_docs()
Expand All @@ -142,6 +165,41 @@ def test_sample_programs_repo_dir(test_repo):
assert test_repo.sample_programs_repo_dir() == SAMPLE_PROGRAMS_TEMP_DIR.name


def test_language_has_docs(test_repo):
language: subete.LanguageCollection = test_repo["Befunge"]
assert language.has_docs()


def test_language_doc_author(test_repo):
language: subete.LanguageCollection = test_repo["Befunge"]
assert "Stuart Irwin" in language.doc_authors()


def test_language_doc_created(test_repo):
language: subete.LanguageCollection = test_repo["Befunge"]
assert language.doc_created() is not None


def test_language_doc_modified(test_repo):
language: subete.LanguageCollection = test_repo["Befunge"]
assert language.doc_modified() is not None


def test_project_doc_author(test_repo):
project: subete.Project = test_repo["Python"]["Selection Sort"].project()
assert "Parker Johansen" in project.doc_authors()


def test_project_doc_created(test_repo):
project: subete.Project = test_repo["Python"]["Selection Sort"].project()
assert project.doc_created() is not None


def test_project_doc_modified(test_repo):
project: subete.Project = test_repo["Python"]["Selection Sort"].project()
assert project.doc_modified() is not None


@pytest.fixture(scope="module")
def test_repo():
with patch("subete.repo.tempfile.TemporaryDirectory") as mock:
Expand Down
54 changes: 54 additions & 0 deletions tests/test_integration_for_bad_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import tempfile
from pathlib import Path

import git
import pytest

import subete


def test_bad_repo_total_projects(bad_test_repo):
assert bad_test_repo.total_approved_projects() == 1


def test_bad_repo_languages(bad_test_repo):
assert len(list(bad_test_repo)) == 1


def test_bad_repo_total_programs(bad_test_repo):
assert bad_test_repo.total_programs() == 1


def test_bad_repo_total_tests(bad_test_repo):
assert bad_test_repo.total_tests() == 0


@pytest.fixture(scope="module")
def bad_test_repo():
with tempfile.TemporaryDirectory() as repo_dir, tempfile.TemporaryDirectory() as website_repo_dir:
# Create repo
repo: git.Repo = git.Repo.init(repo_dir)

archive_dir = f"{repo_dir}/archive/f/foo"
sample_program_file = f"{archive_dir}/whatever.foo"
Path(archive_dir).mkdir(parents=True)
Path(sample_program_file).write_text("hello\n")

repo.index.add([sample_program_file])
repo.index.commit("Initial commit")

# Create website repo
website_repo: git.Repo = git.Repo.init(website_repo_dir)

project_doc_dir = f"{website_repo_dir}/sources/projects/bad"
project_doc_file = f"{project_doc_dir}/something.md"
Path(project_doc_dir).mkdir(parents=True)
Path(project_doc_file).write_text("hello\n")

website_repo.index.add([project_doc_file])
website_repo.index.commit("Initial commit")

yield subete.load(repo_dir, website_repo_dir)

repo.close()
website_repo.close()
16 changes: 13 additions & 3 deletions tests/test_language_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ def test_language_collection_str():
assert str(test) == "Python"


def test_language_collection_name():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test.name() == "Python"


def test_language_collection_test_file():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test.testinfo() != None
assert test.testinfo() is not None


def test_language_collection_readme():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test.readme() != None
assert test.readme() is not None


def test_language_collection_sample_programs():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test != None
assert test is not None
assert subete.SampleProgram(TEST_PATH, TEST_FILES[0], test) in test


Expand All @@ -54,3 +59,8 @@ def test_language_collection_language_url():
def test_missing_programs():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test.missing_programs() == [TEST_PROJECTS[1]]


def test_missing_programs_count():
test = subete.LanguageCollection(TEST_LANG, TEST_PATH, TEST_FILES, TEST_PROJECTS)
assert test.missing_programs_count() == 1
21 changes: 21 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@ def test_project_str():
test = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
assert str(test) == "Hello World"


def test_name():
test = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
assert test.name() == "Hello World"


def test_pathlike_name():
test = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
assert test.pathlike_name() == "hello-world"


def test_has_testing():
test = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
assert test.has_testing()


def test_project_equality():
test1 = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
test2 = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
assert test1 == test2


def test_project_inequality():
test1 = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
test2 = subete.Project("goodbye-world", {"words": ["goodbye", "world"], "requires_parameters": False})
assert test1 != test2


def test_project_diff_class():
test1 = subete.Project("hello-world", {"words": ["hello", "world"], "requires_parameters": False})
test2 = "hello"
assert test1 != test2
28 changes: 28 additions & 0 deletions tests/test_sample_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_sample_program_issue_query_url():
assert test.article_issue_query_url(
) == "https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+hello+world+python"


def test_generate_project_hyphen_branch():
test = subete.SampleProgram(
"tests/c",
Expand All @@ -71,3 +72,30 @@ def test_generate_project_hyphen_branch():
)
)
assert test.project_pathlike_name() == "rot13"


def test_sample_program_equality():
test1 = subete.SampleProgram(TEST_PATH, TEST_FILES[0], TEST_LANG_COLLECTION)
test2 = subete.SampleProgram(TEST_PATH, TEST_FILES[0], TEST_LANG_COLLECTION)
assert test1 == test2


def test_sample_program_inequality():
test1 = subete.SampleProgram(TEST_PATH, TEST_FILES[0], TEST_LANG_COLLECTION)
test2 = subete.SampleProgram(
"tests/c",
"rot13.c",
LanguageCollection(
"c",
"tests/c",
["rot13.c", "testinfo.yml", "README.md"],
TEST_PROJECTS
)
)
assert test1 != test2


def test_sample_program_diff_class():
test1 = subete.SampleProgram(TEST_PATH, TEST_FILES[0], TEST_LANG_COLLECTION)
test2 = "foo"
assert test1 != test2

0 comments on commit 713ebce

Please sign in to comment.