Skip to content

Commit

Permalink
Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Nov 11, 2015
1 parent 0fe54b6 commit f657685
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
12 changes: 6 additions & 6 deletions guessit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ def display_properties(options):

if options.json:
if options.values:
print(json.dumps(properties, ensure_ascii=False))
print(json.dumps(properties, cls=GuessitEncoder, ensure_ascii=False))
else:
print(json.dumps(properties.keys(), ensure_ascii=False))
print(json.dumps(list(properties.keys()), cls=GuessitEncoder, ensure_ascii=False))
elif options.yaml:
import yaml
from guessit import yamlutils
if options.values:
print(yaml.dump(properties, Dumper=yamlutils.CustomDumper, default_flow_style=False, allow_unicode=True))
else:
print(yaml.dump(properties.keys(), Dumper=yamlutils.CustomDumper, default_flow_style=False,
print(yaml.dump(list(properties.keys()), Dumper=yamlutils.CustomDumper, default_flow_style=False,
allow_unicode=True))
else:
print('GuessIt properties:')

properties_list = sorted(properties.keys())
properties_list = list(sorted(properties.keys()))
for property_name in properties_list:
property_values = properties.get(property_name)
print(2 * ' ' + '[+] %s' % (property_name,))
Expand Down Expand Up @@ -128,8 +128,8 @@ def main(args=None): # pylint:disable=too-many-branches
filenames = []
if options.filename:
for filename in options.filename:
encoding = sys.getfilesystemencoding()
if not isinstance(filename, six.text_type):
if not isinstance(filename, six.text_type): # pragma: no cover
encoding = sys.getfilesystemencoding()
filename = filename.decode(encoding)
filenames.append(filename)
if options.input_file:
Expand Down
2 changes: 1 addition & 1 deletion guessit/jsonutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def default(self, o): # pylint:disable=method-hidden
return ret
elif hasattr(o, 'name'): # Babelfish languages/countries long name
return o.name
else:
else: # pragma: no cover
return str(o)
12 changes: 12 additions & 0 deletions guessit/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_main_input():
main(['--input', os.path.join(__location__, 'test-input-file.txt')])


def test_main_properties():
main(['-p'])
main(['-p', '--json'])
main(['-p', '--yaml'])


def test_main_values():
main(['-V'])
main(['-V', '--json'])
main(['-V', '--yaml'])


def test_main_help():
with pytest.raises(SystemExit):
main(['--help'])
Expand Down
4 changes: 2 additions & 2 deletions guessit/yamlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def construct_yaml_map(self, node):
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
else: # pragma: no cover
raise yaml.constructor.ConstructorError(None, None,
'expected a mapping node, but found %s' % node.id, node.start_mark)

Expand All @@ -39,7 +39,7 @@ def construct_mapping(self, node, deep=False):
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc:
except TypeError as exc: # pragma: no cover
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)'
% exc, key_node.start_mark)
Expand Down

0 comments on commit f657685

Please sign in to comment.