Skip to content

Commit

Permalink
chore: Add more code checks - pydocstyle, flake8-comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Oct 19, 2019
1 parent 85a5145 commit da74380
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 214 deletions.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ repos:
language_version: python3
- id: flake8
language_version: python3
additional_dependencies: [flake8-comprehensions]
- repo: https://github.com/asottile/pyupgrade
rev: v1.24.0
rev: v1.24.1
hooks:
- id: pyupgrade
language_version: python3
- repo: https://github.com/pycqa/pydocstyle
rev: 4.0.1
hooks:
- id: pydocstyle
- repo: local
hooks:
- id: system-pylint
Expand Down
4 changes: 1 addition & 3 deletions dump2polarion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Imports.
"""
"""Imports."""

from dump2polarion.configuration import get_config
from dump2polarion.results.importer import import_results
Expand Down
6 changes: 2 additions & 4 deletions dump2polarion/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Configuration loading.
"""
"""Configuration loading."""

import logging
import os
Expand Down Expand Up @@ -123,7 +121,7 @@ def _get_user_conf(config_file):


def get_config(config_file=None, config_values=None, load_project_conf=True):
"""Loads config file and returns its content."""
"""Load config file and return its content."""
config_values = config_values or {}

default_conf = _get_default_conf()
Expand Down
8 changes: 3 additions & 5 deletions dump2polarion/csv2sqlite_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Dump testcases results from a CSV input file to SQLite.
"""
"""Dump testcases results from a CSV input file to SQLite."""

import argparse
import datetime
Expand Down Expand Up @@ -37,7 +35,7 @@ def get_args(args=None):


def dump2sqlite(records, output_file):
"""Dumps tests results to database."""
"""Dump tests results to database."""
results_keys = list(records.results[0].keys())
pad_data = []

Expand Down Expand Up @@ -75,7 +73,7 @@ def dump2sqlite(records, output_file):


def main(args=None):
"""Main function for cli."""
"""Perform main cli functionality."""
args = get_args(args)

utils.init_log(args.log_level)
Expand Down
2 changes: 1 addition & 1 deletion dump2polarion/csv_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@


def get_csv_reader(csvfile, dialect=csv.excel, **kwds):
"""Returns csv reader."""
"""Return csv reader."""
return csv.reader(csvfile, dialect=dialect, **kwds)
32 changes: 17 additions & 15 deletions dump2polarion/dumper_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
Dump data to Polarion Importers.
Dump testcases results from a CSV, SQLite, junit, JSON or Ostriz input file to XUnit file.
Submit XUnit, Testcases or Requirements XML to the Polarion Importers.
"""
Expand Down Expand Up @@ -58,22 +60,22 @@ def get_args(args=None):


def get_submit_args(args):
"""Gets arguments for the `submit_and_verify` method."""
submit_args = dict(
testrun_id=args.testrun_id,
user=args.user,
password=args.password,
no_verify=args.no_verify,
verify_timeout=args.verify_timeout,
log_file=args.job_log,
dry_run=args.dry_run,
)
"""Get arguments for the `submit_and_verify` method."""
submit_args = {
"testrun_id": args.testrun_id,
"user": args.user,
"password": args.password,
"no_verify": args.no_verify,
"verify_timeout": args.verify_timeout,
"log_file": args.job_log,
"dry_run": args.dry_run,
}
submit_args = {k: v for k, v in submit_args.items() if v is not None}
return Box(submit_args, frozen_box=True, default_box=True)


def process_args(args):
"""Processes passed arguments."""
"""Process passed arguments."""
passed_args = args
if isinstance(args, argparse.Namespace):
passed_args = vars(passed_args)
Expand All @@ -84,7 +86,7 @@ def process_args(args):


def get_testrun_id(args, config, records_testrun_id):
"""Returns testrun id."""
"""Return testrun id."""
config_testrun_id = utils.get_testrun_id_config(config)

found_testrun_id = args.testrun_id or records_testrun_id or config_testrun_id
Expand Down Expand Up @@ -113,7 +115,7 @@ def get_testrun_id(args, config, records_testrun_id):


def submit_if_ready(args, submit_args, config):
"""Submits the input XML file if it's already in the expected format."""
"""Submit the input XML file if it's already in the expected format."""
__, ext = os.path.splitext(args.input_file)
if ext.lower() != ".xml":
return None
Expand Down Expand Up @@ -148,7 +150,7 @@ def _get_config(args):


def dumper(args, config, transform_func=None):
"""Dumper main function."""
"""Perform main dumper functionality."""
args = process_args(args)
submit_args = get_submit_args(args)

Expand Down Expand Up @@ -191,7 +193,7 @@ def dumper(args, config, transform_func=None):


def main(args=None, transform_func=None):
"""Main function for cli."""
"""Perform main cli functionality."""
args = get_args(args)

utils.init_log(args.log_level)
Expand Down
4 changes: 1 addition & 3 deletions dump2polarion/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Exceptions.
"""
"""Exceptions."""


class Dump2PolarionException(Exception):
Expand Down
24 changes: 12 additions & 12 deletions dump2polarion/exporters/requirements_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


class RequirementTransform:
"""Transforms requirement data and fills in default keys and values."""
"""Transform requirement data and fill in default keys and values."""

REQ_DATA = {
"approver-ids": None,
Expand Down Expand Up @@ -79,13 +79,13 @@ def _fill_project_defaults(self, testcase_data):
return filled

def _run_transform_func(self, result):
"""Calls transform function on result."""
"""Call transform function on result."""
if self._transform_func:
result = self._transform_func(result)
return result or None

def _fill_polarion_fields(self, req_data):
"""Sets importer field value from polarion field if available."""
"""Set importer field value from polarion field if available."""
for importer_field, polarion_field in self.FIELD_MAPPING.items():
polarion_value = req_data.get(polarion_field)
xml_value = req_data.get(importer_field)
Expand All @@ -101,7 +101,7 @@ def _fill_defaults(self, req_data):
return req_data

def transform(self, req_data):
"""Transforms requirement data."""
"""Transform requirement data."""
req_data = self._fill_project_defaults(req_data)
req_data = self._fill_polarion_fields(req_data)
req_data = self._run_transform_func(req_data)
Expand All @@ -118,7 +118,7 @@ def transform(self, req_data):


class RequirementExport:
"""Exports requirements data into XML representation."""
"""Export requirements data into XML representation."""

def __init__(self, requirements_data, config, transform_func=None):
self.requirements_data = requirements_data
Expand All @@ -130,7 +130,7 @@ def __init__(self, requirements_data, config, transform_func=None):
self.known_custom_fields.update(self.config.get("requirements_custom_fields") or ())

def _top_element(self):
"""Returns top XML element."""
"""Return top XML element."""
attrs = {"project-id": self.config["polarion-project-id"]}
document_relative_path = self.config.get("requirements-document-relative-path")
if document_relative_path:
Expand All @@ -139,7 +139,7 @@ def _top_element(self):
return top

def _properties_element(self, parent_element):
"""Returns properties XML element."""
"""Return properties XML element."""
requirements_properties = etree.SubElement(parent_element, "properties")

req_properties_conf = self.config.get("requirements_import_properties") or {}
Expand All @@ -159,7 +159,7 @@ def _properties_element(self, parent_element):
return requirements_properties

def _fill_lookup_prop(self, requirements_properties):
"""Fills the polarion-lookup-method property."""
"""Fill the polarion-lookup-method property."""
if not self._lookup_prop:
raise Dump2PolarionException("Failed to set the 'polarion-lookup-method' property")

Expand All @@ -170,7 +170,7 @@ def _fill_lookup_prop(self, requirements_properties):
)

def _check_lookup_prop(self, req_id):
"""Checks that selected lookup property can be used for this testcase."""
"""Check that selected lookup property can be used for this testcase."""
if self._lookup_prop:
if not req_id and self._lookup_prop == "id":
return False
Expand Down Expand Up @@ -212,7 +212,7 @@ def _fill_custom_fields(parent, custom_fields):
)

def _requirement_element(self, parent_element, req_data):
"""Adds requirement XML element."""
"""Add requirement XML element."""
req_data = self.requirement_transform.transform(req_data)
if not req_data:
return
Expand Down Expand Up @@ -252,7 +252,7 @@ def _fill_requirements(self, parent_element):
self._requirement_element(parent_element, req_data)

def export(self):
"""Returns requirements XML."""
"""Return requirements XML."""
top = self._top_element()
properties = self._properties_element(top)
self._fill_requirements(top)
Expand All @@ -261,6 +261,6 @@ def export(self):

@staticmethod
def write_xml(xml, output_file=None):
"""Outputs the XML content into a file."""
"""Output the XML content into a file."""
gen_filename = "requirements-{:%Y%m%d%H%M%S}.xml".format(datetime.datetime.now())
utils.write_xml(xml, output_loc=output_file, filename=gen_filename)
30 changes: 15 additions & 15 deletions dump2polarion/exporters/testcases_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


class TestcaseTransform:
"""Transforms testcase data and fills in default keys and values."""
"""Transform testcase data and fill in default keys and values."""

TESTCASE_DATA = {
"approver-ids": None,
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, config, transform_func=None):

@staticmethod
def _get_full_repo_address(repo_address):
"""Makes sure the repo address is complete path in repository.
"""Make sure the repo address is complete path in repository.
>>> TestcaseTransform._get_full_repo_address("https://gitlab.com/somerepo")
'https://gitlab.com/somerepo/blob/master/'
Expand Down Expand Up @@ -143,13 +143,13 @@ def _fill_automation_repo(self, testcase_data):
return testcase_data

def _run_transform_func(self, testcase_data):
"""Calls transform function on testcase data."""
"""Call transform function on testcase data."""
if self._transform_func:
testcase_data = self._transform_func(testcase_data)
return testcase_data or None

def _fill_polarion_fields(self, testcase_data):
"""Sets importer field value from polarion field if available."""
"""Set importer field value from polarion field if available."""
for importer_field, polarion_field in self.FIELD_MAPPING.items():
polarion_value = testcase_data.get(polarion_field)
xml_value = testcase_data.get(importer_field)
Expand All @@ -165,7 +165,7 @@ def _fill_defaults(self, testcase_data):
return testcase_data

def transform(self, testcase_data):
"""Transforms testcase data."""
"""Transform testcase data."""
testcase_data = self._fill_project_defaults(testcase_data)
testcase_data = self._fill_automation_repo(testcase_data)
testcase_data = self._fill_polarion_fields(testcase_data)
Expand All @@ -178,7 +178,7 @@ def transform(self, testcase_data):


class TestcaseExport:
"""Exports testcases data into XML representation."""
"""Export testcases data into XML representation."""

def __init__(self, testcases_data, config, transform_func=None):
self.testcases_data = testcases_data
Expand All @@ -201,13 +201,13 @@ def __init__(self, testcases_data, config, transform_func=None):
)

def _top_element(self):
"""Returns top XML element."""
"""Return top XML element."""
attrs = {"project-id": self.config["polarion-project-id"]}
top = etree.Element("testcases", attrs)
return top

def _properties_element(self, parent_element):
"""Returns properties XML element."""
"""Return properties XML element."""
testcases_properties = etree.SubElement(parent_element, "properties")

testcases_properties_conf = self.config.get("testcase_import_properties") or {}
Expand All @@ -227,7 +227,7 @@ def _properties_element(self, parent_element):
return testcases_properties

def _fill_lookup_prop(self, testcases_properties):
"""Fills the polarion-lookup-method property."""
"""Fill the polarion-lookup-method property."""
if not self._lookup_prop:
raise Dump2PolarionException("Failed to set the 'polarion-lookup-method' property")

Expand All @@ -250,7 +250,7 @@ def _set_lookup_prop(self, testcase_data):
logger.debug("Setting lookup method for testcases to `%s`", self._lookup_prop)

def _check_lookup_prop(self, testcase_data):
"""Checks that selected lookup property can be used for this testcase."""
"""Check that selected lookup property can be used for this testcase."""
if not self._lookup_prop:
return False

Expand All @@ -261,7 +261,7 @@ def _check_lookup_prop(self, testcase_data):
return True

def _get_testcase_id(self, testcase_data):
"""Returns testcase id when possible."""
"""Return testcase id when possible."""
testcase_id = testcase_data.get("id")
if testcase_id:
return testcase_id
Expand Down Expand Up @@ -352,7 +352,7 @@ def _fill_custom_fields(parent, custom_fields):
)

def _is_whitelisted(self, nodeid):
"""Checks if the nodeid is whitelisted."""
"""Check if the nodeid is whitelisted."""
if not nodeid:
return True
if self._compiled_whitelist and self._compiled_whitelist.search(nodeid):
Expand All @@ -362,7 +362,7 @@ def _is_whitelisted(self, nodeid):
return True

def _testcase_element(self, parent_element, testcase_data):
"""Adds testcase XML element."""
"""Add testcase XML element."""
nodeid = testcase_data.get("nodeid")
if not self._is_whitelisted(nodeid):
logger.debug("Skipping blacklisted node: %s", nodeid)
Expand Down Expand Up @@ -412,7 +412,7 @@ def _fill_testcases(self, parent_element):
self._testcase_element(parent_element, testcase_data)

def export(self):
"""Returns testcases XML."""
"""Return testcases XML."""
top = self._top_element()
properties = self._properties_element(top)
self._fill_testcases(top)
Expand All @@ -421,6 +421,6 @@ def export(self):

@staticmethod
def write_xml(xml, output_file=None):
"""Outputs the XML content into a file."""
"""Output the XML content into a file."""
gen_filename = "testcases-{:%Y%m%d%H%M%S}.xml".format(datetime.datetime.now())
utils.write_xml(xml, output_loc=output_file, filename=gen_filename)

0 comments on commit da74380

Please sign in to comment.