Bugfix: default gitignore (#1189)

This commit is contained in:
Elijah Ahianyo 2023-06-13 18:14:57 +00:00 committed by GitHub
parent aa2a1df201
commit fe89d53dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 6 deletions

View File

@ -180,11 +180,11 @@ def initialize_gitignore():
# Subtract current ignored files. # Subtract current ignored files.
if os.path.exists(constants.GITIGNORE_FILE): if os.path.exists(constants.GITIGNORE_FILE):
with open(constants.GITIGNORE_FILE, "r") as f: with open(constants.GITIGNORE_FILE, "r") as f:
files -= set(f.read().splitlines()) files -= set(f.read().replace(" ", "").strip().splitlines())
# Add the new files to the .gitignore file. # Add the new files to the .gitignore file.
with open(constants.GITIGNORE_FILE, "a") as f: with open(constants.GITIGNORE_FILE, "a") as f:
f.write(path_ops.join(files)) f.write(f"\n{path_ops.join(files)}")
def initialize_app_directory(app_name: str, template: constants.Template): def initialize_app_directory(app_name: str, template: constants.Template):

View File

@ -6,8 +6,7 @@ from typing import Any, List, Union
import pytest import pytest
from packaging import version from packaging import version
from pynecone import Env from pynecone import Env, constants
from pynecone.constants import CONFIG_FILE, DB_URL
from pynecone.utils import build, format, imports, prerequisites, types from pynecone.utils import build, format, imports, prerequisites, types
from pynecone.vars import Var from pynecone.vars import Var
@ -426,10 +425,10 @@ def test_create_config_e2e(tmp_working_dir):
app_name = "e2e" app_name = "e2e"
prerequisites.create_config(app_name) prerequisites.create_config(app_name)
eval_globals = {} eval_globals = {}
exec((tmp_working_dir / CONFIG_FILE).read_text(), eval_globals) exec((tmp_working_dir / constants.CONFIG_FILE).read_text(), eval_globals)
config = eval_globals["config"] config = eval_globals["config"]
assert config.app_name == app_name assert config.app_name == app_name
assert config.db_url == DB_URL assert config.db_url == constants.DB_URL
assert config.env == Env.DEV assert config.env == Env.DEV
@ -478,3 +477,38 @@ def test_is_dataframe(class_type, expected):
expected: whether type name is DataFrame expected: whether type name is DataFrame
""" """
assert types.is_dataframe(class_type) == expected assert types.is_dataframe(class_type) == expected
@pytest.mark.parametrize("gitignore_exists", [True, False])
def test_initialize_non_existent_gitignore(tmp_path, mocker, gitignore_exists):
"""Test that the generated .gitignore_file file on pc init contains the correct file
names with correct formatting.
Args:
tmp_path: The root test path.
mocker: The mock object.
gitignore_exists: Whether a gitignore file exists in the root dir.
"""
sep = os.sep
expected = constants.DEFAULT_GITIGNORE.copy()
mocker.patch("pynecone.constants.GITIGNORE_FILE", tmp_path / ".gitignore")
gitignore_file = tmp_path / ".gitignore"
if gitignore_exists:
gitignore_file.touch()
gitignore_file.write_text(
"""
pynecone.db
__pycache__/
"""
)
prerequisites.initialize_gitignore()
assert gitignore_file.exists()
file_content = gitignore_file.open().read()
file_content.replace(f"{sep}{sep}", sep)
assert set(file_content.split()) == expected