diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 102ffb6..7e87133 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,7 @@ jobs: - name: Build local image ${{ matrix.alpine }} run: docker build --build-arg PYTHON_VERSION="${{ matrix.python }}" -t "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" -f Dockerfile--${{ matrix.platform }}.tmpl . - name: Run - run: docker run -t -v ${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}:/home/test/testgres/logs "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" + run: docker run -t -v ${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}:/home/test/project/logs "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" - name: Upload Logs uses: actions/upload-artifact@v7 if: always() # IT IS IMPORTANT! diff --git a/Dockerfile--alpine.tmpl b/Dockerfile--alpine.tmpl index 7593cec..27c5639 100644 --- a/Dockerfile--alpine.tmpl +++ b/Dockerfile--alpine.tmpl @@ -13,8 +13,8 @@ RUN apk add bash RUN adduser -D test -ADD --chown=test:test . /home/test/testgres -WORKDIR /home/test/testgres +ADD --chown=test:test . /home/test/project +WORKDIR /home/test/project USER test diff --git a/Dockerfile--astralinux_1_7.tmpl b/Dockerfile--astralinux_1_7.tmpl index f1db1e3..b346e0e 100644 --- a/Dockerfile--astralinux_1_7.tmpl +++ b/Dockerfile--astralinux_1_7.tmpl @@ -15,10 +15,10 @@ FROM base2_with_python-${PYTHON_VERSION} AS final RUN useradd -m test -ADD --chown=test:test . /home/test/testgres -WORKDIR /home/test/testgres -RUN mkdir /home/test/testgres/logs -RUN chown -R test:test /home/test/testgres/logs +ADD --chown=test:test . /home/test/project +WORKDIR /home/test/project +RUN mkdir /home/test/project/logs +RUN chown -R test:test /home/test/project/logs ENV LANG=C.UTF-8 diff --git a/pyproject.toml b/pyproject.toml index f974df2..913d377 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ classifiers = [ ] dependencies = [ + "testgres.common>=1.0.3,<2.0.0", ] [project.urls] diff --git a/src/core/raise_error.py b/src/core/raise_error.py index 29b1c5f..a3f6959 100644 --- a/src/core/raise_error.py +++ b/src/core/raise_error.py @@ -1,6 +1,8 @@ # ////////////////////////////////////////////////////////////////////////////// # Postgres Pro. PostgreSQL Configuration Python Library. +from ..exceptions import PostgresConfigException + import datetime import typing @@ -44,7 +46,10 @@ def GetPropertyIsNotImplemented( @staticmethod def OptionNameIsNone() -> typing.NoReturn: errMsg = "Option name is None." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -54,22 +59,31 @@ def OptionNameHasBadType( assert nameType is not None assert type(nameType) is type - errMsg = "Option name has nad type [{}]".format( + errMsg = "Option name has a nad type [{}]".format( nameType.__name__, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def OptionNameIsEmpty() -> typing.NoReturn: errMsg = "Option name is empty." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def NoneValueIsNotSupported() -> typing.NoReturn: errMsg = "None value is not supported." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -82,37 +96,55 @@ def NoneOptionValueItemIsNotSupported( errMsg = "None value item of option [{}] is not supported.".format( optionName, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def CommentObjectWasDeleted() -> typing.NoReturn: errMsg = "Comment object was deleted." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def OptionObjectWasDeleted() -> typing.NoReturn: errMsg = "Option object was deleted." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def IncludeObjectWasDeleted() -> typing.NoReturn: errMsg = "Include object was deleted." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def FileLineObjectWasDeleted() -> typing.NoReturn: errMsg = "FileLine object was deleted." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def FileObjectWasDeleted() -> typing.NoReturn: errMsg = "File object was deleted." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -130,7 +162,10 @@ def BadOptionValueType( optionValueType.__name__, expectedType.__name__, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -148,7 +183,10 @@ def CantConvertOptionValue( sourceType.__name__, targetType.__name__, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -166,13 +204,19 @@ def BadOptionValueItemType( optionValueItemType.__name__, expectedType.__name__, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def CommentTextContainsInvalidSymbols() -> typing.NoReturn: errMsg = "Comment text contains invalid symbols." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -180,7 +224,10 @@ def FileIsAlreadyRegistered( file_path: str, ) -> typing.NoReturn: errMsg = "File [{0}] is already registered.".format(file_path) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -196,7 +243,10 @@ def OptionIsAlreadyExistInThisFile( errMsg = "Option [{0}] already exist in this file [{1}].".format( optionName, filePath ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -213,7 +263,10 @@ def OptionIsAlreadyExistInAnotherFile( optionName, filePath, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -230,7 +283,10 @@ def OptionIsAlreadyExistInFile( optionName, filePath, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -247,7 +303,10 @@ def OptionValueItemIsAlreadyDefined( optName, valueItem, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -264,7 +323,10 @@ def OptionValueItemIsAlreadyDefinedInAnotherFile( valueItem, filePath, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -274,7 +336,10 @@ def UnknownFileName(fileName: str) -> typing.NoReturn: errMsg = "Unknown file name [{}].".format( fileName, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -289,13 +354,19 @@ def MultipleDefOfFileIsFound( fileName, count, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def FilePathIsEmpty() -> typing.NoReturn: errMsg = "File path is empty." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -313,13 +384,19 @@ def FileWasModifiedExternally( ourLastMDate, curLastMDate, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def FileLineAlreadyHasComment() -> typing.NoReturn: errMsg = "File line already has a comment." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -329,14 +406,19 @@ def FileLineAlreadyHasOption(optionName: str) -> typing.NoReturn: errMsg = "File line already has the option [{}].".format( optionName, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def FileLineAlreadyHasIncludeDirective() -> typing.NoReturn: errMsg = "File line already has an include directive." - raise Exception(errMsg) + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -354,7 +436,10 @@ def CfgReader__UnexpectedSymbol( colNum, ch, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -365,7 +450,10 @@ def CfgReader__IncludeWithoutPath(lineNum: int) -> typing.NoReturn: errMsg = "Include directive in line {} does not have a path.".format( lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -376,7 +464,10 @@ def CfgReader__EndOfIncludePathIsNotFound(lineNum: int) -> typing.NoReturn: errMsg = "The end of an include path is not found. Line {}.".format( lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -387,7 +478,10 @@ def CfgReader__IncompletedEscapeInInclude(lineNum: int) -> typing.NoReturn: errMsg = "Escape in an include path is not completed. Line {}.".format( lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -410,7 +504,10 @@ def CfgReader__UnknownEscapedSymbolInInclude( colNum, ) ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -423,7 +520,10 @@ def CfgReader__IncludeHasEmptyPath( errMsg = "Include in line {} has an empty path.".format( lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -440,7 +540,10 @@ def CfgReader__OptionWithoutValue( optionName, lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -457,7 +560,10 @@ def CfgReader__EndQuotedOptionValueIsNotFound( optionName, lineNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -476,7 +582,10 @@ def CfgReader__IncompletedEscapeInQuotedOptionValue( lineNum, ) ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod @@ -499,13 +608,28 @@ def CfgReader__UnknownEscapedSymbolInQuotedOptionValue( lineNum, colNum, ) - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) # -------------------------------------------------------------------- @staticmethod def BadFormatOfCommaSeparatedList() -> typing.NoReturn: errMsg = "Bad format of comma separated list." - raise Exception(errMsg) + + __class__.Helper__RaiseErr__PostgresConfigException( + errMsg, + ) + + # -------------------------------------------------------------------- + @staticmethod + def Helper__RaiseErr__PostgresConfigException( + errMsg: str, + ) -> typing.NoReturn: + assert type(errMsg) is str + + raise PostgresConfigException(errMsg) # ////////////////////////////////////////////////////////////////////////////// diff --git a/src/exceptions.py b/src/exceptions.py new file mode 100644 index 0000000..1af1b92 --- /dev/null +++ b/src/exceptions.py @@ -0,0 +1,16 @@ +# ////////////////////////////////////////////////////////////////////////////// +# Postgres Pro. PostgreSQL Configuration Python Library. + +from testgres.common.exceptions import TestgresException + +# ////////////////////////////////////////////////////////////////////////////// +# PostgresConfigException + + +class PostgresConfigException(TestgresException): + """Base class for all Postgres configuration errors""" + + pass + + +# ////////////////////////////////////////////////////////////////////////////// diff --git a/tests/exceptions/PostrgresConfigurationException/__init__.py b/tests/exceptions/PostrgresConfigurationException/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/exceptions/PostrgresConfigurationException/test_set001__constructor.py b/tests/exceptions/PostrgresConfigurationException/test_set001__constructor.py new file mode 100644 index 0000000..67957b7 --- /dev/null +++ b/tests/exceptions/PostrgresConfigurationException/test_set001__constructor.py @@ -0,0 +1,26 @@ +from src.exceptions import PostgresConfigException + + +class TestSet001_Constructor: + def test_001_positional_args_000(self): + e = PostgresConfigException() + assert e.message == "" + assert e.source is None + assert str(e) == "" + return + + def test_001_positional_args_001__arg1(self): + e = PostgresConfigException("abcdef") + assert e.message == "abcdef" + assert e.source is None + assert str(e) == "abcdef" + assert repr(e) == "PostgresConfigException('abcdef')" + return + + def test_001_positional_args_002__arg1_arg2(self): + e = PostgresConfigException("abc123", "mysource") + assert e.message == "('abc123', 'mysource')" + assert e.source is None + assert str(e) == "('abc123', 'mysource')" + assert repr(e) == "PostgresConfigException('abc123', 'mysource')" + return diff --git a/tests/exceptions/PostrgresConfigurationException/test_set002__usage.py b/tests/exceptions/PostrgresConfigurationException/test_set002__usage.py new file mode 100644 index 0000000..7d4fb36 --- /dev/null +++ b/tests/exceptions/PostrgresConfigurationException/test_set002__usage.py @@ -0,0 +1,37 @@ +from src.exceptions import PostgresConfigException + + +class TestSet002__usage: + def test_001__str_and_repr(self): + class EEE(PostgresConfigException): + @property + def message(self) -> str: + return "EEE!\neee?" + + e = EEE("abc321\n123cba") + assert isinstance(e, PostgresConfigException) + assert e.message == "EEE!\neee?" + assert e.source is None + assert str(e) == "EEE!\neee?" + # It a default implementation + assert repr(e) == "EEE('abc321\\n123cba')" + return + + def test_002__str_and_repr(self): + class EEE(PostgresConfigException): + def __init__(self): + super().__init__("zxc", "321") + return + + @property + def message(self) -> str: + return "EEE!\neee?" + + e = EEE() + assert isinstance(e, PostgresConfigException) + assert e.message == "EEE!\neee?" + assert e.source is None + assert str(e) == "EEE!\neee?" + # It a default implementation + assert repr(e) == "EEE('zxc', '321')" + return diff --git a/tests/exceptions/__init__.py b/tests/exceptions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/requirements.txt b/tests/requirements.txt index cbe2395..300d084 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,4 @@ pytest pytest-env pytest-xdist +testgres.common>=1.0.3,<2.0.0