Skip to content

Commit

Permalink
Ref. #71
Browse files Browse the repository at this point in the history
Use isinstance for type comparison
Catch possible key error
  • Loading branch information
cosmingrz committed Mar 11, 2017
1 parent d12ab5c commit 0198b6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ env:
matrix:
- USE_YAML=1
python:
- '2.7.11'
- '3.5'
- pypy
- pypy3
install:
- pip install -r requirements/base.txt;
- if [[ $USE_SQLALCHEMY == false ]]; then pip install pymysql; fi
Expand All @@ -25,8 +28,4 @@ install:
before_script:
- if [[ $USE_SQLALCHEMY == false ]]; then mysql -u root -e 'create database spampad;'; fi
script:
- env USE_PICKLES=0 py.test tests/functional/test_plugins/test_dkim.py
- cat tests/test_match_conf/20.yaml
- cat tests/test_match_conf/v310.yml
- cat tests/test_match_conf/v320.yml
- ls tests/test_match_conf/
- env USE_PICKLES=0 py.test tests/functional/test_plugins/test_dkim.py
14 changes: 8 additions & 6 deletions pad/rules/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ def parse_file(self, filename, _depth=0):
return
with open(filename, "rb") as rulef:
# Extract file extension
extension = filename.rsplit(".")[1]
base_name, extension = os.path.splitext(filename)

# Parse YML configuration file
if extension in ("yml", "yaml"):
if extension in (".yml", ".yaml"):
chunk = str()

# Since the parsing order counts we cannot load the
Expand Down Expand Up @@ -195,7 +195,7 @@ def parse_file(self, filename, _depth=0):
def _handle_yaml_element(self, yaml_dict, _depth):
"""Method that adds the YAML parsed element to the self.results"""

if not type(yaml_dict) is dict:
if not isinstance(yaml_dict, dict):
return

for key, value in yaml_dict.items():
Expand All @@ -215,7 +215,7 @@ def _handle_yaml_element(self, yaml_dict, _depth):
self.ctxt.hook_parse_config("report", desc)

# If the element is a dict maybe it can describe a rule
elif type(value) is dict:
elif isinstance(value, dict):

# If the rule is not present in the results
if key not in self.results:
Expand All @@ -240,9 +240,11 @@ def _handle_yaml_element(self, yaml_dict, _depth):
# set the target
if value[param].startswith("eval:"):
try:
self.results[key]["target"] = self.results[key]["type"]
self.results[key]["target"] = \
self.results[key]["type"]
except KeyError:
raise Exception('Results: %s -> %s', self.results, value)
self.results[key]["target"] = value["type"]

self.results[key]["type"] = "eval"
self.results[key]["value"] = value[param]

Expand Down
16 changes: 8 additions & 8 deletions tests/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def setUp(self):

def tearDown(self):
unittest.TestCase.tearDown(self)
# try:
# shutil.rmtree(self.test_conf, True)
# except OSError:
# pass
# try:
# shutil.rmtree(self.debug_email)
# except OSError:
# pass
try:
shutil.rmtree(self.test_conf, True)
except OSError:
pass
try:
shutil.rmtree(self.debug_email)
except OSError:
pass

def setup_conf(self, config=DEFAULT_CONFIG, pre_config=DEFAULT_PRE_CONFIG):
"""Setup the configuration folder with the specified
Expand Down

0 comments on commit 0198b6b

Please sign in to comment.