From 26a851bfc2cc85ecd76cd0f610d2669940d1da02 Mon Sep 17 00:00:00 2001 From: rzuckerm Date: Sat, 1 Apr 2023 16:03:04 -0500 Subject: [PATCH] Add ability to get sample program repository directory (#58) --- docs/changelog.rst | 6 +++ setup.py | 2 +- subete/repo.py | 8 +++ tests/test_integration.py | 110 ++++++++++++++++++++++---------------- 4 files changed, 80 insertions(+), 46 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4b6e11f..7a7d585 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 ------ diff --git a/setup.py b/setup.py index ca0ab2f..541a71f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description = fh.read() MAJOR = 0 -MINOR = 14 +MINOR = 15 PATCH = 0 name = "subete" diff --git a/subete/repo.py b/subete/repo.py index c7472dd..17d20a7 100644 --- a/subete/repo.py +++ b/subete/repo.py @@ -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. diff --git a/tests/test_integration.py b/tests/test_integration.py index 5e566d6..09b4240 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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()