Coverage for tests\test_hassle.py: 100%

1 import pytest

2 from pathier import Pathier

3

4 from hassle import utilities

5 from hassle.models import HassleConfig, HassleProject, Pyproject

6

7 root = Pathier(__file__).parent

8

9

10@pytest.fixture(scope="module")

11 def userdir(tmp_path_factory) -> Pathier:

12 userdir = Pathier(tmp_path_factory.mktemp("user"))

13 userdir.mkcwd()

14 return userdir

15

16

17@pytest.fixture(scope="module")

18 def dummy_projectdir(userdir: Pathier) -> Pathier:

19 dir_ = userdir / "dummy"

20 dir_.mkdir()

21 return dir_

22

23

24@pytest.fixture(scope="module")

25 def config_path(userdir: Pathier) -> Pathier:

26 return userdir / "hassle_config.toml"

27

28

29 def test__config_set_config(config_path: Pathier):

30 assert not HassleConfig.exists(config_path)

31 HassleConfig.configure(

32 "yeehaw", "yeehaw@yeet.com", "big_boi", None, "UwU", config_path

33 )

34 assert HassleConfig.exists(config_path)

35

36

37 def test__config(config_path: Pathier):

38 config_ = HassleConfig.load(config_path)

39 assert config_.authors

40 assert config_.authors[0].name == "yeehaw"

41 assert config_.authors[0].email == "yeehaw@yeet.com"

42 assert config_.project_urls.Homepage == "https://github.com/big_boi/$name"

43 assert config_.git.tag_prefix == "UwU"

44

45

46 def test__pyproject():

47 pyproject = Pyproject.from_template()

48 assert pyproject

49

50

51 def test__hassleproject(dummy_projectdir: Pathier, config_path: Pathier):

52 name = dummy_projectdir.stem

53 pyproject = Pyproject.from_template()

54 config = HassleConfig.load(config_path)

55 pyproject.project.name = name

56 pyproject.project.authors = config.authors

57 for url in dir(config.project_urls):

58 if not url.startswith("_"):

59 setattr(

60 pyproject.project.urls,

61 url,

62 getattr(config.project_urls, url).replace("$name", name),

63 )

64 hassle = HassleProject(pyproject, dummy_projectdir, ["__init__.py", f"{name}.py"])

65 hassle.generate_files()

66 for f in dummy_projectdir.rglob("*"):

67 print(f)

68 for file in [

69 "pyproject.toml",

70 ".gitignore",

71 "README.md",

72 "LICENSE.txt",

73 ".vscode/settings.json",

74 f"tests/test_{name}.py",

75 ]:

76 assert (dummy_projectdir / file).exists()

77 print((dummy_projectdir / "pyproject.toml").read_text())

78

79

80 def test__utilities_bump_version():

81 version = "0.0.0"

82 version = utilities.bump_version(version, "major")

83 assert version == "1.0.0"

84 version = utilities.bump_version(version, "minor")

85 assert version == "1.1.0"

86 version = utilities.bump_version(version, "patch")

87 assert version == "1.1.1"