Coverage for tests/test_generation/test_utils.py: 100%
34 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1import pytest
3from prisma.generator.utils import (
4 copy_tree,
5 to_camel_case,
6 to_snake_case,
7 to_pascal_case,
8 to_constant_case,
9)
11from ..utils import Testdir
14def test_copy_tree_ignores_files(testdir: Testdir) -> None:
15 """Ensure *.pyc and __pycache__ files are not copied"""
16 p1 = testdir.path / 'p1'
17 p1.mkdir()
18 p1.joinpath('foo.pyc').touch()
19 p1.joinpath('foo.py').touch()
20 p1.joinpath('bar.py').touch()
21 p1.joinpath('__pycache__').mkdir()
22 p1.joinpath('__pycache__/hello.py').touch()
23 assert len(list(p1.glob('**/*'))) == 5
25 p2 = testdir.path / 'p2'
26 p2.mkdir()
27 p2.joinpath('hello.py').touch()
28 assert len(list(p2.glob('**/*'))) == 1
30 copy_tree(p1, p2)
32 files = sorted(list(p2.glob('**/*')))
33 assert len(files) == 3
34 assert files[0].name == 'bar.py'
35 assert files[1].name == 'foo.py'
36 assert files[2].name == 'hello.py'
39@pytest.mark.parametrize(
40 'input_str,expected',
41 [
42 ('snake_case_test', 'snake_case_test'),
43 ('PascalCaseTest', 'pascal_case_test'),
44 ('camelCaseTest', 'camel_case_test'),
45 ('Mixed_Case_Test', 'mixed_case_test'),
46 ],
47)
48def test_to_snake_case(input_str: str, expected: str) -> None:
49 assert to_snake_case(input_str) == expected
52@pytest.mark.parametrize(
53 'input_str,expected',
54 [
55 ('snake_case_test', 'SnakeCaseTest'),
56 ('PascalCaseTest', 'PascalCaseTest'),
57 ('camelCaseTest', 'CamelCaseTest'),
58 ('Mixed_Case_Test', 'MixedCaseTest'),
59 ],
60)
61def test_to_pascal_case(input_str: str, expected: str) -> None:
62 assert to_pascal_case(input_str) == expected
65@pytest.mark.parametrize(
66 'input_str,expected',
67 [
68 ('snake_case_test', 'snakeCaseTest'),
69 ('PascalCaseTest', 'pascalCaseTest'),
70 ('camelCaseTest', 'camelCaseTest'),
71 ('Mixed_Case_Test', 'mixedCaseTest'),
72 ],
73)
74def test_to_camel_case(input_str: str, expected: str) -> None:
75 assert to_camel_case(input_str) == expected
78@pytest.mark.parametrize(
79 'input_str,expected',
80 [
81 ('snake_case_test', 'SNAKE_CASE_TEST'),
82 ('PascalCaseTest', 'PASCAL_CASE_TEST'),
83 ('camelCaseTest', 'CAMEL_CASE_TEST'),
84 ('Mixed_Case_Test', 'MIXED_CASE_TEST'),
85 ],
86)
87def test_to_constant_case(input_str: str, expected: str) -> None:
88 assert to_constant_case(input_str) == expected