- Notifications
You must be signed in to change notification settings - Fork37
Proposal to fix #154 (v2)#161
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
dmitry-lipetsk merged 13 commits intopostgrespro:masterfromdmitry-lipetsk:master-fix154--v02Dec 10, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
13 commits Select commitHold shift + click to select a range
f9ddd04 Proposal to fix #154 (v2)
dmitry-lipetsk2bb38dc [BUG FIX] PostgresNode::safe_psql did not respect "expect_error" para…
dmitry-lipetsk45b8dc0 [BUG FIX] A problem in psql/safe_psql and 'input' data was fixed [loc…
dmitry-lipetskf848a63 PostgresNode::safe_psql raises InvalidOperationException
dmitry-lipetskdb0744e A problem with InvalidOperationException and flake8 is fixed
dmitry-lipetsk5bb1510 A code style is fixed [flake8]
dmitry-lipetsk31c7bce [BUG FIX] Wrappers for psql use subprocess.PIPE for stdout and stderr
dmitry-lipetskb013801 [BUG FIX] TestgresTests::test_safe_psql__expect_error uses rm_carriag…
dmitry-lipetskc49ee4c node.py is updated [formatting]
dmitry-lipetsk6a0e714 Formatting
dmitry-lipetsk3cc19d2 raise_error.py is moved into testgres/operations from testgres/helpers
dmitry-lipetsk7b70e9e Helpers.GetDefaultEncoding is added
dmitry-lipetskcd0b5f8 Code normalization
dmitry-lipetskFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 3 additions & 2 deletionstestgres/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletionstestgres/exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,13 +9,14 @@ class TestgresException(Exception): | ||
| @six.python_2_unicode_compatible | ||
| classExecUtilException(TestgresException): | ||
| def__init__(self,message=None,command=None,exit_code=0,out=None,error=None): | ||
| super(ExecUtilException,self).__init__(message) | ||
| self.message=message | ||
| self.command=command | ||
| self.exit_code=exit_code | ||
| self.out=out | ||
| self.error=error | ||
| def__str__(self): | ||
| msg= [] | ||
| @@ -24,13 +25,17 @@ def __str__(self): | ||
| msg.append(self.message) | ||
| ifself.command: | ||
| command_s=' '.join(self.command)ifisinstance(self.command,list)elseself.command, | ||
| msg.append(u'Command: {}'.format(command_s)) | ||
| ifself.exit_code: | ||
| msg.append(u'Exit code: {}'.format(self.exit_code)) | ||
| ifself.error: | ||
| msg.append(u'---- Error:\n{}'.format(self.error)) | ||
| ifself.out: | ||
| msg.append(u'---- Out:\n{}'.format(self.out)) | ||
| returnself.convert_and_join(msg) | ||
| @@ -98,3 +103,7 @@ class InitNodeException(TestgresException): | ||
| classBackupException(TestgresException): | ||
| pass | ||
| classInvalidOperationException(TestgresException): | ||
| pass | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
81 changes: 56 additions & 25 deletionstestgres/node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletionstestgres/operations/helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| importlocale | ||
| classHelpers: | ||
| def_make_get_default_encoding_func(): | ||
| # locale.getencoding is added in Python 3.11 | ||
| ifhasattr(locale,'getencoding'): | ||
| returnlocale.getencoding | ||
| # It must exist | ||
| returnlocale.getpreferredencoding | ||
| # Prepared pointer on function to get a name of system codepage | ||
| _get_default_encoding_func=_make_get_default_encoding_func() | ||
| defGetDefaultEncoding(): | ||
| # | ||
| # Original idea/source was: | ||
| # | ||
| # def os_ops.get_default_encoding(): | ||
| # if not hasattr(locale, 'getencoding'): | ||
| # locale.getencoding = locale.getpreferredencoding | ||
| # return locale.getencoding() or 'UTF-8' | ||
| # | ||
| assert__class__._get_default_encoding_funcisnotNone | ||
| r=__class__._get_default_encoding_func() | ||
| ifr: | ||
| assertrisnotNone | ||
| asserttype(r)==str# noqa: E721 | ||
| assertr!="" | ||
| returnr | ||
| # Is it an unexpected situation? | ||
| return'UTF-8' | ||
| defPrepareProcessInput(input,encoding): | ||
| ifnotinput: | ||
| returnNone | ||
| iftype(input)==str:# noqa: E721 | ||
| ifencodingisNone: | ||
| returninput.encode(__class__.GetDefaultEncoding()) | ||
| asserttype(encoding)==str# noqa: E721 | ||
| returninput.encode(encoding) | ||
| # It is expected! | ||
| asserttype(input)==bytes# noqa: E721 | ||
| returninput |
44 changes: 30 additions & 14 deletionstestgres/operations/local_ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletionstestgres/operations/raise_error.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from ..exceptions import ExecUtilException | ||
| from .helpers import Helpers | ||
| class RaiseError: | ||
| def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out): | ||
| assert type(exit_code) == int # noqa: E721 | ||
| msg_arg_s = __class__._TranslateDataIntoString(msg_arg).strip() | ||
| assert type(msg_arg_s) == str # noqa: E721 | ||
| if msg_arg_s == "": | ||
| msg_arg_s = "#no_error_message" | ||
| message = "Utility exited with non-zero code. Error: `" + msg_arg_s + "`" | ||
| raise ExecUtilException( | ||
| message=message, | ||
| command=cmd, | ||
| exit_code=exit_code, | ||
| out=out, | ||
| error=error) | ||
| def _TranslateDataIntoString(data): | ||
| if type(data) == bytes: # noqa: E721 | ||
| return __class__._TranslateDataIntoString__FromBinary(data) | ||
| return str(data) | ||
| def _TranslateDataIntoString__FromBinary(data): | ||
| assert type(data) == bytes # noqa: E721 | ||
| try: | ||
| return data.decode(Helpers.GetDefaultEncoding()) | ||
| except UnicodeDecodeError: | ||
| pass | ||
| return "#cannot_decode_text" | ||
| def _BinaryIsASCII(data): | ||
| assert type(data) == bytes # noqa: E721 | ||
| for b in data: | ||
| if not (b >= 0 and b <= 127): | ||
| return False | ||
| return True |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.