From e6db097702f0f557bf538942094e690c8ecb9a46 Mon Sep 17 00:00:00 2001 From: Natalia Maximo Date: Fri, 9 Jul 2021 11:04:46 -0400 Subject: [PATCH] chg: added pre-commit fixes on all files that needed them (#31) --- .gitignore | 2 +- .pre-commit-config.yaml | 3 --- MANIFEST.in | 2 +- SECURITY.md | 2 +- scripts/process_release.py | 4 ++-- src/pytest_quilla/__init__.py | 8 +++---- src/pytest_quilla/pytest_classes.py | 2 +- src/quilla/__init__.py | 4 ++-- src/quilla/__main__.py | 2 +- src/quilla/common/enums.py | 30 ++++++++++++------------- src/quilla/common/exceptions.py | 2 +- src/quilla/ctx.py | 4 ++-- src/quilla/reports/base_report.py | 8 +++---- src/quilla/reports/report_summary.py | 18 +++++++-------- src/quilla/reports/validation_report.py | 20 ++++++++--------- src/quilla/steps/base_steps.py | 6 ++--- src/quilla/steps/outputs.py | 4 ++-- src/quilla/steps/steps.py | 4 ++-- src/quilla/steps/steps_aggregator.py | 2 +- src/quilla/ui_validation.py | 8 +++---- tests/conftest.py | 8 +++---- tests/test_utils.py | 8 +++---- 22 files changed, 74 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 5391d87..a81c8ee 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,4 @@ dmypy.json .pytype/ # Cython debug symbols -cython_debug/ \ No newline at end of file +cython_debug/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5a4cb6..bcf24c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,3 @@ repos: - id: detect-private-key - id: double-quote-string-fixer - id: end-of-file-fixer - - id: fix-encoding-pragma - - id: name-tests-test - - id: trailing-whitespace diff --git a/MANIFEST.in b/MANIFEST.in index 150d74b..11a5eb0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -graft src \ No newline at end of file +graft src diff --git a/SECURITY.md b/SECURITY.md index f7b8998..926b8ae 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -38,4 +38,4 @@ We prefer all communications to be in English. Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). - \ No newline at end of file + diff --git a/scripts/process_release.py b/scripts/process_release.py index 728110e..2ba4768 100644 --- a/scripts/process_release.py +++ b/scripts/process_release.py @@ -5,7 +5,7 @@ import re release_json = sys.argv[1] platform = sys.argv[2] -asset_regex = re.compile(f"{platform}.tar.gz$") +asset_regex = re.compile(f'{platform}.tar.gz$') with open(release_json) as f: release_data = json.load(f) @@ -18,7 +18,7 @@ for data in release_data: break if release is None: - print("") + print('') sys.exit(1) for asset in release['assets']: diff --git a/src/pytest_quilla/__init__.py b/src/pytest_quilla/__init__.py index a89097d..6e60fb9 100644 --- a/src/pytest_quilla/__init__.py +++ b/src/pytest_quilla/__init__.py @@ -29,10 +29,10 @@ def pytest_load_initial_conftests(early_config: Config, parser: Parser): return parser.addoption( - "--quilla-opts", - action="store", - default="", - help="Options to be passed through to the quilla runtime for the scenario tests" + '--quilla-opts', + action='store', + default='', + help='Options to be passed through to the quilla runtime for the scenario tests' ) diff --git a/src/pytest_quilla/pytest_classes.py b/src/pytest_quilla/pytest_classes.py index 76ce07e..528a48c 100644 --- a/src/pytest_quilla/pytest_classes.py +++ b/src/pytest_quilla/pytest_classes.py @@ -25,7 +25,7 @@ def collect_file(parent: pytest.Session, path: LocalPath, prefix: str): ''' # TODO: change "path" to be "fspath" when pytest 6.3 is released: # https://docs.pytest.org/en/latest/_modules/_pytest/hookspec.html#pytest_collect_file - if path.ext == ".json" and path.basename.startswith(prefix): + if path.ext == '.json' and path.basename.startswith(prefix): return QuillaFile.from_parent(parent, fspath=path) diff --git a/src/quilla/__init__.py b/src/quilla/__init__.py index 79ca765..5afe1de 100644 --- a/src/quilla/__init__.py +++ b/src/quilla/__init__.py @@ -50,11 +50,11 @@ def make_parser() -> argparse.ArgumentParser: # pragma: no cover parser.add_argument( '--debug', action='store_true', - help="Enable debug mode", + help='Enable debug mode', ) parser.add_argument( '--driver-dir', - dest="drivers_path", + dest='drivers_path', action='store', default='.', help='The directory where browser drivers are stored', diff --git a/src/quilla/__main__.py b/src/quilla/__main__.py index bb9c8ef..e8611f6 100644 --- a/src/quilla/__main__.py +++ b/src/quilla/__main__.py @@ -1,5 +1,5 @@ import quilla # pragma: no cover -if __name__ == "__main__": # pragma: no cover +if __name__ == '__main__': # pragma: no cover quilla.run() diff --git a/src/quilla/common/enums.py b/src/quilla/common/enums.py index 03d5e07..43d93c7 100644 --- a/src/quilla/common/enums.py +++ b/src/quilla/common/enums.py @@ -63,33 +63,33 @@ class UITestActions(Enum): WAIT_FOR_VISIBILITY = 'WaitForVisibility' NAVIGATE_TO = 'NavigateTo' VALIDATE = 'Validate' - REFRESH = "Refresh" - ADD_COOKIES = "AddCookies" - SET_COOKIES = "SetCookies" - REMOVE_COOKIE = "RemoveCookie" - CLEAR_COOKIES = "ClearCookies" - NAVIGATE_FORWARD = "NavigateForward" - NAVIGATE_BACK = "NavigateBack" - SET_BROWSER_SIZE = "SetBrowserSize" - HOVER = "Hover" - OUTPUT_VALUE = "OutputValue" + REFRESH = 'Refresh' + ADD_COOKIES = 'AddCookies' + SET_COOKIES = 'SetCookies' + REMOVE_COOKIE = 'RemoveCookie' + CLEAR_COOKIES = 'ClearCookies' + NAVIGATE_FORWARD = 'NavigateForward' + NAVIGATE_BACK = 'NavigateBack' + SET_BROWSER_SIZE = 'SetBrowserSize' + HOVER = 'Hover' + OUTPUT_VALUE = 'OutputValue' class ReportType(Enum): ''' All the currently supported report types ''' - VALIDATION = "Validation" - STEP_FAILURE = "StepFailure" + VALIDATION = 'Validation' + STEP_FAILURE = 'StepFailure' class BrowserTargets(Enum): ''' All the currently supported browser targets ''' - FIREFOX = "Firefox" - CHROME = "Chrome" - EDGE = "Edge" + FIREFOX = 'Firefox' + CHROME = 'Chrome' + EDGE = 'Edge' class OutputSources(Enum): diff --git a/src/quilla/common/exceptions.py b/src/quilla/common/exceptions.py index 5710454..b8cf287 100644 --- a/src/quilla/common/exceptions.py +++ b/src/quilla/common/exceptions.py @@ -19,7 +19,7 @@ class NoDriverException(UIValidationException): ''' def __init__(self): - super().__init__("No driver currently bound") + super().__init__('No driver currently bound') class FailedStepException(UIValidationException): diff --git a/src/quilla/ctx.py b/src/quilla/ctx.py index 5a2449b..943f61a 100644 --- a/src/quilla/ctx.py +++ b/src/quilla/ctx.py @@ -55,7 +55,7 @@ class Context(DriverHolder): logger: A logger instance. If None was passed in for the 'logger' argument, will create one with the default logger. ''' - default_context: Optional["Context"] = None + default_context: Optional['Context'] = None _drivers_path: str _expression_regex = re.compile(r'\${{(.*)}}') _context_obj_expression = re.compile( @@ -135,7 +135,7 @@ class Context(DriverHolder): return v def _set_path(self): - os.environ['PATH'] = f"{self._path}:{self._drivers_path}" + os.environ['PATH'] = f'{self._path}:{self._drivers_path}' @lru_cache def perform_replacements(self, text: str) -> str: diff --git a/src/quilla/reports/base_report.py b/src/quilla/reports/base_report.py index ac647cd..d6ce83c 100644 --- a/src/quilla/reports/base_report.py +++ b/src/quilla/reports/base_report.py @@ -23,14 +23,14 @@ class BaseReport(EnumResolver): msg: A string giving further context to the report ''' - def __init__(self, report_type: ReportType, browser: str, action: UITestActions, msg: str = ""): + def __init__(self, report_type: ReportType, browser: str, action: UITestActions, msg: str = ''): self.browser: str = browser self.action: UITestActions = action self.msg: str = msg self.report_type: ReportType = report_type @abstractclassmethod - def from_dict(cls, report: Dict[str, Dict[str, str]]) -> "BaseReport": + def from_dict(cls, report: Dict[str, Dict[str, str]]) -> 'BaseReport': ''' Converts a dictionary report into a valid Report object @@ -53,7 +53,7 @@ class BaseReport(EnumResolver): return json.dumps(report) @classmethod - def from_json(cls, report_json: str) -> "BaseReport": + def from_json(cls, report_json: str) -> 'BaseReport': ''' Loads a valid json string and attempts to convert it into a Report object @@ -64,7 +64,7 @@ class BaseReport(EnumResolver): return cls.from_dict(st) # type: ignore @classmethod - def from_file(cls, fp) -> "BaseReport": + def from_file(cls, fp) -> 'BaseReport': ''' Converts a fp (a file-like .read() supporting object) containing a json document into a Report object diff --git a/src/quilla/reports/report_summary.py b/src/quilla/reports/report_summary.py index f2c3fa6..8daa51e 100644 --- a/src/quilla/reports/report_summary.py +++ b/src/quilla/reports/report_summary.py @@ -108,10 +108,10 @@ class ReportSummary: For example, to filter by only successful reports you would call `reports.filter_by.success()` ''' - def __init__(self, summary: "ReportSummary"): + def __init__(self, summary: 'ReportSummary'): self._summary = summary - def _filter(self, condition: Callable[[BaseReport], bool]) -> "ReportSummary": + def _filter(self, condition: Callable[[BaseReport], bool]) -> 'ReportSummary': ''' Returns a new summary with only reports that match the condition passed as a lambda function parameter @@ -121,7 +121,7 @@ class ReportSummary: return ReportSummary(list(filtered_reports)) - def state(self, state: str) -> "ReportSummary": + def state(self, state: str) -> 'ReportSummary': ''' Returns: a new summary with only reports that have a state matching the one @@ -131,7 +131,7 @@ class ReportSummary: lambda x: isinstance(x, ValidationReport) and x.state.lower() == state ) - def browser(self, browser: str) -> "ReportSummary": + def browser(self, browser: str) -> 'ReportSummary': ''' Returns: a new summary with only reports that have a browser matching the one @@ -139,21 +139,21 @@ class ReportSummary: ''' return self._filter(lambda x: x.browser.lower() == browser.lower()) - def successful(self) -> "ReportSummary": + def successful(self) -> 'ReportSummary': ''' Returns: a new summary with only the reports that produced a success ''' return self._filter(lambda x: isinstance(x, ValidationReport) and x.success) - def failure(self) -> "ReportSummary": + def failure(self) -> 'ReportSummary': ''' Returns: a new summary with only the reports that produced a failure ''' return self._filter(lambda x: isinstance(x, ValidationReport) and not x.success) - def type(self, validation_type: str) -> "ReportSummary": + def type(self, validation_type: str) -> 'ReportSummary': ''' Returns: a new summary with only reports that have a type matching the one @@ -165,7 +165,7 @@ class ReportSummary: x.validation_type.lower() == validation_type.lower() ) - def target(self, target: str) -> "ReportSummary": + def target(self, target: str) -> 'ReportSummary': ''' Returns: a new summary with only reports that have a target matching the one @@ -175,7 +175,7 @@ class ReportSummary: lambda x: isinstance(x, ValidationReport) and x.target.lower() == target.lower() ) - def critical_failure(self) -> "ReportSummary": + def critical_failure(self) -> 'ReportSummary': ''' Returns: a new summary with only reports that constitute a critical failure diff --git a/src/quilla/reports/validation_report.py b/src/quilla/reports/validation_report.py index 6845055..72d57d5 100644 --- a/src/quilla/reports/validation_report.py +++ b/src/quilla/reports/validation_report.py @@ -32,7 +32,7 @@ class ValidationReport(BaseReport): state: str, browser_name: str, success: bool, - msg: str = "" + msg: str = '' ): super().__init__( ReportType.VALIDATION, @@ -46,7 +46,7 @@ class ValidationReport(BaseReport): self.success = success @classmethod - def from_dict(cls, report) -> "ValidationReport": + def from_dict(cls, report) -> 'ValidationReport': ''' Converts a dictionary into a ValidationReport object @@ -54,7 +54,7 @@ class ValidationReport(BaseReport): report: ''' params = report['validationReport'] - msg = "" + msg = '' if 'msg' in params: msg = params['msg'] return ValidationReport( @@ -71,13 +71,13 @@ class ValidationReport(BaseReport): Returns a dictionary representation of the object ''' report = { - "validationReport": { - "action": self.action.value, - "type": self.validation_type, - "target": self.target, - "state": self.state, - "targetBrowser": self.browser, - "passed": self.success, + 'validationReport': { + 'action': self.action.value, + 'type': self.validation_type, + 'target': self.target, + 'state': self.state, + 'targetBrowser': self.browser, + 'passed': self.success, } } diff --git a/src/quilla/steps/base_steps.py b/src/quilla/steps/base_steps.py index 5a89551..f9d8dde 100644 --- a/src/quilla/steps/base_steps.py +++ b/src/quilla/steps/base_steps.py @@ -66,7 +66,7 @@ class BaseStep(DriverHolder, EnumResolver): pass @abstractmethod - def copy(self) -> "BaseStep": + def copy(self) -> 'BaseStep': ''' Returns a copy of the current Step object ''' @@ -188,7 +188,7 @@ class BaseValidation(BaseStep): self._selector = selector self._report: Optional[ValidationReport] = None - def copy(self) -> "BaseValidation": + def copy(self) -> 'BaseValidation': # All classes derived from BaseValidation only need these parameters return self.__class__( # type: ignore self.ctx, # type: ignore @@ -216,7 +216,7 @@ class BaseValidation(BaseStep): return self._report - def _create_report(self, success: bool, msg: str = "") -> ValidationReport: + def _create_report(self, success: bool, msg: str = '') -> ValidationReport: ''' Creates a new validation report. Used to simplify the common shared behaviour that all validation reports require diff --git a/src/quilla/steps/outputs.py b/src/quilla/steps/outputs.py index e18fb08..6b34541 100644 --- a/src/quilla/steps/outputs.py +++ b/src/quilla/steps/outputs.py @@ -29,7 +29,7 @@ class OutputValueStep(BaseStep, BaseStepFactory): ctx: Context, action_dict: Dict, driver: Optional[WebDriver] = None - ) -> "BaseStep": + ) -> 'BaseStep': ''' Factory method to extract needed parameters from a dictionary ''' @@ -87,7 +87,7 @@ class OutputValueStep(BaseStep, BaseStepFactory): return self.element.get_property(property_name) - def copy(self) -> "OutputValueStep": + def copy(self) -> 'OutputValueStep': ''' Creates a shallow copy of the OutputValueStep object diff --git a/src/quilla/steps/steps.py b/src/quilla/steps/steps.py index 9727539..a85fe0c 100644 --- a/src/quilla/steps/steps.py +++ b/src/quilla/steps/steps.py @@ -71,7 +71,7 @@ class TestStep(BaseStep, BaseStepFactory): ctx: Context, action_dict, driver: Optional[WebDriver] = None - ) -> "TestStep": + ) -> 'TestStep': ''' Factory method to extract needed parameters from a dictionary ''' @@ -117,7 +117,7 @@ class TestStep(BaseStep, BaseStepFactory): UITestActions.REMOVE_COOKIE: self._remove_cookie, } - def copy(self) -> "TestStep": + def copy(self) -> 'TestStep': ''' Creates a shallow copy of the TestStep object diff --git a/src/quilla/steps/steps_aggregator.py b/src/quilla/steps/steps_aggregator.py index 40322ac..ad9ec3b 100644 --- a/src/quilla/steps/steps_aggregator.py +++ b/src/quilla/steps/steps_aggregator.py @@ -110,7 +110,7 @@ class StepsAggregator(DriverHolder): return reports - def copy(self) -> "StepsAggregator": + def copy(self) -> 'StepsAggregator': ''' Creates a copy of the StepsAggregator object diff --git a/src/quilla/ui_validation.py b/src/quilla/ui_validation.py index b9e50f8..84ee063 100644 --- a/src/quilla/ui_validation.py +++ b/src/quilla/ui_validation.py @@ -49,14 +49,14 @@ class QuillaTest(EnumResolver): } @classmethod - def from_json(cls, ctx: Context, validation_json: str) -> "QuillaTest": # pragma: no cover + def from_json(cls, ctx: Context, validation_json: str) -> 'QuillaTest': # pragma: no cover ''' Converts a json string into a UIValidation object ''' return QuillaTest.from_dict(ctx, json.loads(validation_json)) @classmethod - def from_file(cls, ctx: Context, fp) -> "QuillaTest": # pragma: no cover + def from_file(cls, ctx: Context, fp) -> 'QuillaTest': # pragma: no cover ''' Converts an fp (a .read() supporting file-like object) containing a json document into a UIValidation object @@ -64,7 +64,7 @@ class QuillaTest(EnumResolver): return QuillaTest.from_dict(ctx, json.load(fp)) @classmethod - def from_filename(cls, ctx: Context, path: str) -> "QuillaTest": # pragma: no cover + def from_filename(cls, ctx: Context, path: str) -> 'QuillaTest': # pragma: no cover ''' Reads a file at the specified path and attempts to convert it into a UIValidation object @@ -73,7 +73,7 @@ class QuillaTest(EnumResolver): return QuillaTest.from_file(ctx, fp) @classmethod - def from_dict(cls, ctx: Context, validation_parameters: dict) -> "QuillaTest": + def from_dict(cls, ctx: Context, validation_parameters: dict) -> 'QuillaTest': ''' Converts a dictionary that represents a single UIValidation test case into the appropriate validation object. diff --git a/tests/conftest.py b/tests/conftest.py index 7eeef1e..37f7310 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -46,10 +46,10 @@ def driver(): def pytest_addoption(parser, pluginmanager: PytestPluginManager): pluginmanager.set_blocked('quilla') parser.addoption( - "--quilla-opts", - action="store", - default="", - help="Options to be passed through to the quilla runtime for the scenario tests" + '--quilla-opts', + action='store', + default='', + help='Options to be passed through to the quilla runtime for the scenario tests' ) diff --git a/tests/test_utils.py b/tests/test_utils.py index f112c2c..1295967 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,11 +32,11 @@ class UtilTests: def test_driverholder_returns_expected(self): holder = DriverHolder() - holder.driver = "Some Value" + holder.driver = 'Some Value' - assert holder.driver == "Some Value" + assert holder.driver == 'Some Value' - @pytest.mark.parametrize("enum_type", [ + @pytest.mark.parametrize('enum_type', [ enums.UITestActions, enums.XPathValidationStates, enums.URLValidationStates, @@ -49,7 +49,7 @@ class UtilTests: for val in enum_type: assert resolver._name_to_enum(val.value, enum_type) is val - @pytest.mark.parametrize("enum_type", [ + @pytest.mark.parametrize('enum_type', [ enums.UITestActions, enums.XPathValidationStates, enums.URLValidationStates,