Revert changes to file conftest.py

This commit is contained in:
mannaandpoem 2024-01-09 10:49:10 +08:00
parent 8851147df7
commit 7a5485bc8b

View file

@ -6,6 +6,7 @@
@File : test_incremental_dev.py
"""
import os
import subprocess
import pytest
from typer.testing import CliRunner
@ -33,8 +34,15 @@ def test_refined_simple_calculator():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_number_guessing_game():
@ -53,8 +61,42 @@ def test_refined_number_guessing_game():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_word_cloud():
project_path = f"{DATA_PATH}/word_cloud"
check_or_create_base_tag(project_path)
args = [
"Add a feature to remove deprecated words from the word cloud. The current word cloud generator does not support removing deprecated words. Now, The word cloud generator should support removing deprecated words. Customize deactivated words to exclude them from word cloud. Let users see all the words in the text file, and allow users to select the words they want to remove.",
"--inc",
"--project-path",
project_path,
]
result = runner.invoke(app, args)
logger.info(result)
logger.info(result.output)
if "Aborting" in result.output:
assert False
else:
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_dice_simulator_1():
@ -73,8 +115,15 @@ def test_refined_dice_simulator_1():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_1")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_1"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_dice_simulator_2():
@ -93,8 +142,15 @@ def test_refined_dice_simulator_2():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_2")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_2"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_dice_simulator_3():
@ -113,8 +169,15 @@ def test_refined_dice_simulator_3():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_3")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_3"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_pygame_2048_1():
@ -133,8 +196,15 @@ def test_refined_pygame_2048_1():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_1")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_1"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_pygame_2048_2():
@ -153,8 +223,15 @@ def test_refined_pygame_2048_2():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_2")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_2"], check=True)
except subprocess.CalledProcessError as e:
raise e
def test_refined_pygame_2048_3():
@ -173,48 +250,15 @@ def test_refined_pygame_2048_3():
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_3")
assert True
def test_refined_word_cloud_1():
project_path = f"{DATA_PATH}/word_cloud"
check_or_create_base_tag(project_path)
args = [
"Add a feature to remove deprecated words from the word cloud. The current word cloud generator does not support removing deprecated words. Now, The word cloud generator should support removing deprecated words. Customize deactivated words to exclude them from word cloud. Let users see all the words in the text file, and allow users to select the words they want to remove.",
"--inc",
"--project-path",
project_path,
]
result = runner.invoke(app, args)
logger.info(result)
logger.info(result.output)
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_1")
assert True
def test_refined_word_cloud_2():
project_path = f"{DATA_PATH}/word_cloud"
check_or_create_base_tag(project_path)
args = [
"Add a feature to customize the resolution of the word cloud.The new version allows users to customize the size and resolution of the generated word cloud after uploading a text file, and then generate the word cloud.",
"--inc",
"--project-path",
project_path,
]
result = runner.invoke(app, args)
logger.info(result)
logger.info(result.output)
if "Aborting" in result.output:
assert False
else:
os.system("git tag refine_2")
assert True
tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip()
if tag == "base":
assert False
else:
assert True
try:
subprocess.run(["git", "tag", "refine_3"], check=True)
except subprocess.CalledProcessError as e:
raise e
def check_or_create_base_tag(project_path):
@ -222,47 +266,50 @@ def check_or_create_base_tag(project_path):
os.chdir(project_path)
# Initialize a Git repository
os.system("git init")
subprocess.run(["git", "init"], check=True)
# Check if the 'base' tag exists
check_base_tag_cmd = "git show-ref --verify --quiet refs/tags/base"
has_base_tag = os.system(check_base_tag_cmd) == 0
check_base_tag_cmd = ["git", "show-ref", "--verify", "--quiet", "refs/tags/base"]
if subprocess.run(check_base_tag_cmd).returncode == 0:
has_base_tag = True
else:
has_base_tag = False
if has_base_tag:
logger.info("Base tag exists")
# Switch to the 'base' branch if it exists
stash_cmd = "git stash"
switch_to_base_branch_cmd = "git checkout base"
stash_cmd = ["git", "stash"]
switch_to_base_branch_cmd = ["git", "checkout", "-f", "base"]
try:
os.system(stash_cmd)
os.system(switch_to_base_branch_cmd)
subprocess.run(stash_cmd, check=True)
subprocess.run(switch_to_base_branch_cmd, check=True)
logger.info("Switched to base branch")
except Exception as e:
logger.info("Failed to switch to base branch")
logger.error("Failed to switch to base branch")
raise e
else:
logger.info("Base tag doesn't exist.")
# Add and commit the current code if 'base' tag doesn't exist
add_cmd = "git add ."
commit_cmd = 'git commit -m "Initial commit"'
add_cmd = ["git", "add", "."]
commit_cmd = ["git", "commit", "-m", "Initial commit"]
try:
os.system(add_cmd)
os.system(commit_cmd)
subprocess.run(add_cmd, check=True)
subprocess.run(commit_cmd, check=True)
logger.info("Added and committed all files with the message 'Initial commit'.")
except Exception as e:
logger.info("Failed to add and commit all files.")
logger.error("Failed to add and commit all files.")
raise e
# Add 'base' tag
add_base_tag_cmd = "git tag base"
add_base_tag_cmd = ["git", "tag", "base"]
# Check if the 'git tag' command was successful
try:
os.system(add_base_tag_cmd)
subprocess.run(add_base_tag_cmd, check=True)
logger.info("Added 'base' tag.")
except Exception as e:
logger.info("Failed to add 'base' tag.")
logger.error("Failed to add 'base' tag.")
raise e