def test_asset_credits_with(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "2f1f4fb") assert len(pc.assets_credits) == 1 credit = pc.assets_credits[0] assert credit.asset_basenames == ["bell-ping.mp3"] assert credit.asset_usage == "the project" assert "candle damper" in credit.credit_markdown
def test_identifier_slug_without(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "ae1fea2c9f21") assert not pc.has_identifier_slug assert pc.maybe_identifier_slug is None with pytest.raises(TCE.InternalError, match="commit .* has no identifier"): pc.identifier_slug
def test_whether_adds_tutorial_assets_root_commit(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "156e4b616fce") assert not pc.adds_tutorial_assets
def test_asset_credits_without(self, this_raw_repo, caplog): with caplog.at_level(logging.WARNING): pc = TH.ProjectCommit(this_raw_repo, "9b40818") assert len(pc.assets_credits) == 0 assert "has no body" in caplog.text
def test_message_body_rejects(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "d5f7ae0") with pytest.raises(TCE.TutorialStructureError, match="malformed commit message"): pc.message_body
def test_message_body(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "2f1f4fb") assert pc.message_body.startswith("This sound")
def test_str(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "ae1fea2") assert str(pc) == "<ProjectCommit: ae1fea2c9f21 BASE>"
def test_short_oid(self, this_raw_repo): # Construct commit from shorter-than-short oid: pc = TH.ProjectCommit(this_raw_repo, "ae1fea2") assert pc.short_oid == "ae1fea2c9f21"
def test_diff_against_parent_or_empty_root_commit(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "156e4b616fce") assert len(pc.diff_against_parent_or_empty) == 0
def test_diff_against_parent_or_empty(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "fd166346") diff = pc.diff_against_parent_or_empty assert len(diff) == 1 delta = list(diff.deltas)[0] assert delta.status == pygit2.GIT_DELTA_MODIFIED
def test_modifies_python_code_no(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "9b4081817626") assert not pc.modifies_python_code
def test_modifies_python_code_yes(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be03") assert pc.modifies_python_code
def test_modifies_tutorial_text_no(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be03") assert not pc.modifies_tutorial_text
def test_modifies_tutorial_text_yes(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e1655214c662") assert pc.modifies_tutorial_text
def test_whether_adds_tutorial_assets_error(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "6b71bac9f1c1") with pytest.raises(TCE.TutorialStructureError, match="tutorial assets but also has"): pc.adds_tutorial_assets
def test_text_file_contents(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "fd16634610de") assert pc.text_file_contents("boing/code.py") == "import pytch\n"
def test_text_file_contents_missing(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "fd16634610de") with pytest.raises(TCE.TutorialStructureError, match="file .* not found"): assert pc.text_file_contents("boing/no-such-file.txt")
def test_sole_modify_against_parent(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be03") assert pc.sole_modify_against_parent.old_file.path == "boing/code.py"
def test_summary_label(self, this_raw_repo, oid, exp_summary): pc = TH.ProjectCommit(this_raw_repo, oid) assert pc.summary_label == exp_summary
def test_sole_modify_against_parent_not_sole(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "c2642880a6fc") with pytest.raises(TCE.TutorialStructureError, match="not have exactly one"): pc.sole_modify_against_parent
def test_message_subject(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "ae1fea2c9f21") assert pc.message_subject == "{base} Add empty code file"
def test_sole_modify_against_parent_not_modified(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "ae1fea2") with pytest.raises(TCE.TutorialStructureError, match="not of type MODIFIED"): pc.sole_modify_against_parent
def test_message_body_empty(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "9b40818") assert pc.message_body == ""
def test_added_assets_one_asset(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "9b40818176") got_assets = pc.added_assets assert len(got_assets) == 1 assert got_assets[0].path == "boing/project-assets/graphics/alien.png" assert got_assets[0].data == b"This is not a real PNG file!"
def test_added_assets_no_assets(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "fd166346") assert pc.added_assets == []
def test_code_patch(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be") patch = pc.code_patch_against_parent context, n_adds, n_dels = patch.line_stats assert n_adds == 4 assert n_dels == 0
def test_identifier_slug_with(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be") assert pc.has_identifier_slug assert pc.maybe_identifier_slug == "add-Alien-skeleton" assert pc.identifier_slug == "add-Alien-skeleton"
def test_code_patch_error(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "9b40818176") with pytest.raises(TCE.TutorialStructureError, match="does not modify the Python code"): pc.code_patch_against_parent
def test_base_detection_yes(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "ae1fea2c9f21") assert pc.is_base
def test_whether_adds_tutorial_assets_no(self, this_raw_repo): pc = TH.ProjectCommit(this_raw_repo, "e41e02c9be03") assert not pc.adds_tutorial_assets