Skip to content

Commit

Permalink
Add ability to get sample program repository directory (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
rzuckerm authored Apr 1, 2023
1 parent 9b00bd8 commit 26a851b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 46 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
Below you'll find all the changes that have been made to the code with
newest changes first.

0.15.x
------

* v0.15.0
* Added ability to get sample program repository directory

0.14.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 = 14
MINOR = 15
PATCH = 0

name = "subete"
Expand Down
8 changes: 8 additions & 0 deletions subete/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def __iter__(self) -> iter:
"""
return iter(self._languages.values())

def sample_programs_repo_dir(self) -> str:
"""
Retreives the directory containing the sample programs repository
:return: the sample programs repository directory
"""
return self._sample_programs_repo_dir

def total_programs(self) -> int:
"""
Retrieves the total number of programs in the sample programs repo.
Expand Down
110 changes: 65 additions & 45 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,135 @@
from unittest.mock import patch
import tempfile

import pytest

import subete

TEST_REPO = subete.load()
SAMPLE_PROGRAMS_TEMP_DIR = tempfile.TemporaryDirectory()
SAMPLE_PROGRAMS_WEBSITE_TEMP_DIR = tempfile.TemporaryDirectory()


def test_doc_url_multiword_lang():
language: subete.LanguageCollection = TEST_REPO["Google Apps Script"]
def test_doc_url_multiword_lang(test_repo):
language: subete.LanguageCollection = test_repo["Google Apps Script"]
assert language.lang_docs_url() == "https://sampleprograms.io/languages/google-apps-script"


def test_doc_url_symbol_lang():
language: subete.LanguageCollection = TEST_REPO["C#"]
def test_doc_url_symbol_lang(test_repo):
language: subete.LanguageCollection = test_repo["C#"]
assert language.lang_docs_url() == "https://sampleprograms.io/languages/c-sharp"


def test_testinfo_url_multiword_lang():
language: subete.LanguageCollection = TEST_REPO["Google Apps Script"]
def test_testinfo_url_multiword_lang(test_repo):
language: subete.LanguageCollection = test_repo["Google Apps Script"]
assert language.testinfo_url(
) == "https://github.com/TheRenegadeCoder/sample-programs/blob/main/archive/g/google-apps-script/testinfo.yml"


def test_testinfo_url_symbol_lang():
language: subete.LanguageCollection = TEST_REPO["C#"]
def test_testinfo_url_symbol_lang(test_repo):
language: subete.LanguageCollection = test_repo["C#"]
assert language.testinfo_url(
) == "https://github.com/TheRenegadeCoder/sample-programs/blob/main/archive/c/c-sharp/testinfo.yml"


def test_requirements_url_multiword_lang():
program: subete.SampleProgram = TEST_REPO["Google Apps Script"]["Hello World"]
def test_requirements_url_multiword_lang(test_repo):
program: subete.SampleProgram = test_repo["Google Apps Script"]["Hello World"]
assert program.project().requirements_url(
) == "https://sampleprograms.io/projects/hello-world"


def test_requirements_url_symbol_lang():
program: subete.SampleProgram = TEST_REPO["C#"]["Hello World"]
def test_requirements_url_symbol_lang(test_repo):
program: subete.SampleProgram = test_repo["C#"]["Hello World"]
assert program.project().requirements_url(
) == "https://sampleprograms.io/projects/hello-world"


def test_documentation_url_multiword_lang():
program: subete.SampleProgram = TEST_REPO["Google Apps Script"]["Hello World"]
def test_documentation_url_multiword_lang(test_repo):
program: subete.SampleProgram = test_repo["Google Apps Script"]["Hello World"]
assert program.documentation_url(
) == "https://sampleprograms.io/projects/hello-world/google-apps-script"


def test_documentation_url_symbol_lang():
program: subete.SampleProgram = TEST_REPO["C#"]["Hello World"]
def test_documentation_url_symbol_lang(test_repo):
program: subete.SampleProgram = test_repo["C#"]["Hello World"]
assert program.documentation_url(
) == "https://sampleprograms.io/projects/hello-world/c-sharp"


def test_article_issue_url_multiword_lang():
program: subete.SampleProgram = TEST_REPO["Google Apps Script"]["Hello World"]
def test_article_issue_url_multiword_lang(test_repo):
program: subete.SampleProgram = test_repo["Google Apps Script"]["Hello World"]
assert program.article_issue_query_url(
) == "https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+hello+world+google+apps+script"


def test_article_issue_url_symbol_lang():
program: subete.SampleProgram = TEST_REPO["C#"]["Hello World"]
def test_article_issue_url_symbol_lang(test_repo):
program: subete.SampleProgram = test_repo["C#"]["Hello World"]
assert program.article_issue_query_url(
) == "https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+hello+world+c#"


def test_authors():
program: subete.SampleProgram = TEST_REPO["Python"]["Hello World"]
def test_authors(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert "Jeremy Griffith" in program.authors()


def test_created_not_none():
program: subete.SampleProgram = TEST_REPO["Python"]["Hello World"]
def test_created_not_none(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.created() is not None


def test_modified_not_none():
program: subete.SampleProgram = TEST_REPO["Python"]["Hello World"]
def test_modified_not_none(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.modified() is not None


def test_code():
program: subete.SampleProgram = TEST_REPO["Python"]["Hello World"]
def test_code(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.code() == "print('Hello, World!')\n"


def test_project_has_test():
program: subete.SampleProgram = TEST_REPO["Google Apps Script"]["Hello World"]
def test_project_has_test(test_repo):
program: subete.SampleProgram = test_repo["Google Apps Script"]["Hello World"]
assert program.project().has_testing()


def test_repo_languages():
assert len(list(TEST_REPO)) > 0
def test_repo_languages(test_repo):
assert len(list(test_repo)) > 0


def test_repo_total_programs():
assert TEST_REPO.total_programs() > 0
def test_repo_total_programs(test_repo):
assert test_repo.total_programs() > 0


def test_repo_total_tests():
assert TEST_REPO.total_tests() > 0
def test_repo_total_tests(test_repo):
assert test_repo.total_tests() > 0


def test_repo_languages_by_letter():
assert len(TEST_REPO.languages_by_letter("p")) > 0
def test_repo_languages_by_letter(test_repo):
assert len(test_repo.languages_by_letter("p")) > 0


def test_random_program():
assert TEST_REPO.random_program() != TEST_REPO.random_program()
def test_random_program(test_repo):
assert test_repo.random_program() != test_repo.random_program()


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


def test_program_has_docs():
program: subete.SampleProgram = TEST_REPO["Python"]["Hello World"]
def test_program_has_docs(test_repo):
program: subete.SampleProgram = test_repo["Python"]["Hello World"]
assert program.has_docs()


def test_sample_programs_repo_dir(test_repo):
assert test_repo.sample_programs_repo_dir() == SAMPLE_PROGRAMS_TEMP_DIR.name


@pytest.fixture(scope="module")
def test_repo():
with patch("subete.repo.tempfile.TemporaryDirectory") as mock:
mock.side_effect = [SAMPLE_PROGRAMS_TEMP_DIR, SAMPLE_PROGRAMS_WEBSITE_TEMP_DIR]
yield subete.load()

SAMPLE_PROGRAMS_TEMP_DIR.cleanup()
SAMPLE_PROGRAMS_WEBSITE_TEMP_DIR.cleanup()

0 comments on commit 26a851b

Please sign in to comment.