Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format Diff to be able to be applied with patch -s -p0 < file.patch #66

Open
cleder opened this issue Oct 7, 2024 · 0 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest

Comments

@cleder
Copy link
Owner

cleder commented Oct 7, 2024

crepr add tests/classes/*.py --diff
should produce:

diff --git a/tests/classes/class_without_repr.py b/tests/classes/class_without_repr.py
index e98cb0b..bb19906 100644
--- a/tests/classes/class_without_repr.py
+++ b/tests/classes/class_without_repr.py
@@ -12,3 +12,9 @@ class MyClassWithoutRepr:
     def __init__(self: Self, value: str) -> None:
         """Initialize the class with the given value."""
         self.value = value
+
+    def __repr__(self) -> str:
+        """Create a string (c)representation for MyClassWithoutRepr."""
+        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
+            f'value={self.value!r}, '
+        ')')
diff --git a/tests/classes/existing_repr_test.py b/tests/classes/existing_repr_test.py
index 004e416..1beb132 100644
--- a/tests/classes/existing_repr_test.py
+++ b/tests/classes/existing_repr_test.py
@@ -23,6 +23,13 @@ class NoRepr:
         """Initialize the class."""
         self.name = name
 
+    def __repr__(self) -> str:
+        """Create a string (c)representation for NoRepr."""
+        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
+            f'name={self.name!r}, '
+        ')')
+
+
 
 @dataclasses.dataclass
 class TestDataClass:
@@ -35,4 +42,4 @@ class TestDataClass:
 class TestDataClassFrozen:
     """A simple frozen dataclass for testing ignore existing flag."""
 
-    number: int
+    number: int
\ No newline at end of file
diff --git a/tests/classes/kw_only_test.py b/tests/classes/kw_only_test.py
index 72565b3..79733cf 100644
--- a/tests/classes/kw_only_test.py
+++ b/tests/classes/kw_only_test.py
@@ -10,3 +10,10 @@ class KwOnly:
         """Initialize the class."""
         self.name = name  # pragma: no cover
         self.age = age  # pragma: no cover
+
+    def __repr__(self) -> str:
+        """Create a string (c)representation for KwOnly."""
+        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
+            f'name={self.name!r}, '
+            f'age={self.age!r}, '
+        ')')
diff --git a/tests/classes/splat_kwargs_test.py b/tests/classes/splat_kwargs_test.py
index 0584692..8e766a6 100644
--- a/tests/classes/splat_kwargs_test.py
+++ b/tests/classes/splat_kwargs_test.py
@@ -10,3 +10,10 @@ class SplatKwargs:
         """Initialize the class."""
         self.name = name  # pragma: no cover
         self.kwargs = kwargs  # pragma: no cover
+
+    def __repr__(self) -> str:
+        """Create a string (c)representation for SplatKwargs."""
+        return (f'{self.__class__.__module__}.{self.__class__.__name__}('
+            f'name={self.name!r}, '
+            f'**{},'
+        ')')

and crepr remove tests/classes/*.py --diff

diff --git a/tests/classes/class_with_repr_test.py b/tests/classes/class_with_repr_test.py
index 334e901..5de1dfc 100644
--- a/tests/classes/class_with_repr_test.py
+++ b/tests/classes/class_with_repr_test.py
@@ -12,11 +12,3 @@ class MyClassWithRepr:
     def __init__(self: Self, value: str) -> None:
         """Initialize the class with the given value."""
         self.value = value
-
-    def __repr__(self: Self) -> str:
-        """Create a string (c)representation for MyClassWithRepr."""
-        return (
-            f"{self.__class__.__module__}.{self.__class__.__name__}("
-            f"value={self.value!r}, "
-            ")"
-        )
diff --git a/tests/classes/class_without_repr.py b/tests/classes/class_without_repr.py
index e98cb0b..b3a35cb 100644
--- a/tests/classes/class_without_repr.py
+++ b/tests/classes/class_without_repr.py
@@ -11,4 +11,4 @@ class MyClassWithoutRepr:
 
     def __init__(self: Self, value: str) -> None:
         """Initialize the class with the given value."""
-        self.value = value
+        self.value = value
\ No newline at end of file
diff --git a/tests/classes/existing_repr_test.py b/tests/classes/existing_repr_test.py
index 004e416..a03e6b8 100644
--- a/tests/classes/existing_repr_test.py
+++ b/tests/classes/existing_repr_test.py
@@ -11,9 +11,6 @@ class ExistingRepr:
         """Initialize the class."""
         self.name = name
 
-    def __repr__(self: Self) -> str:
-        """Existing repr magic method of the class."""
-        return f"ExistingRepr(name={self.name!r})"
 
 
 class NoRepr:
@@ -35,4 +32,4 @@ class TestDataClass:
 class TestDataClassFrozen:
     """A simple frozen dataclass for testing ignore existing flag."""
 
-    number: int
+    number: int
\ No newline at end of file
diff --git a/tests/classes/kw_only_test.py b/tests/classes/kw_only_test.py
index 72565b3..7c37b74 100644
--- a/tests/classes/kw_only_test.py
+++ b/tests/classes/kw_only_test.py
@@ -9,4 +9,4 @@ class KwOnly:
     def __init__(self: Self, name: str, *, age: int) -> None:
         """Initialize the class."""
         self.name = name  # pragma: no cover
-        self.age = age  # pragma: no cover
+        self.age = age  # pragma: no cover
\ No newline at end of file
diff --git a/tests/classes/splat_kwargs_test.py b/tests/classes/splat_kwargs_test.py
index 0584692..3cec523 100644
--- a/tests/classes/splat_kwargs_test.py
+++ b/tests/classes/splat_kwargs_test.py
@@ -9,4 +9,4 @@ class SplatKwargs:
     def __init__(self: Self, name: str, **kwargs: int) -> None:
         """Initialize the class."""
         self.name = name  # pragma: no cover
-        self.kwargs = kwargs  # pragma: no cover
+        self.kwargs = kwargs  # pragma: no cover
\ No newline at end of file

Nnot sure if all of the above is needed, the diff was created by applying the changes and using git--diff
I am not sure if e.g: \ No newline at end of file and index 72565b3..7c37b74 100644, etc. is needed.

@cleder cleder added enhancement New feature or request good first issue Good for newcomers hacktoberfest labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest
Projects
None yet
Development

No branches or pull requests

1 participant