GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — adding more test coverage · adjust/deepdiff@2e59739

This repository was archived by the owner on Dec 11, 2023. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • deepdiff
    • commands.py
    • serialization.py
  • tests
    • fixtures
      • t1_corrupt.json
    • test_command.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎deepdiff/commands.py‎

Copy file name to clipboardExpand all lines: deepdiff/commands.py
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@click.group()
1414
def deepdiff_cli():
1515
"""A simple command line tool."""
16-
pass
16+
pass # pragma: no cover.
1717

1818

1919
# cutoff_intersection_for_pairs=CUTOFF_INTERSECTION_FOR_PAIRS_DEFAULT,
@@ -54,15 +54,12 @@ def diff(
5454
t2_path = kwargs.pop("t2")
5555
t1_extension = t1_path.split('.')[-1]
5656
t2_extension = t2_path.split('.')[-1]
57-
try:
58-
kwargs['t1'] = load_path_content(t1_path, file_type=t1_extension)
59-
except Exception as e:
60-
sys.exit(str(f"Error when loading t1: {e}"))
6157

62-
try:
63-
kwargs['t2'] = load_path_content(t2_path, file_type=t2_extension)
64-
except Exception as e:
65-
sys.exit(str(f"Error when loading t2: {e}"))
58+
for name, t_path, t_extension in [('t1', t1_path, t1_extension), ('t2', t2_path, t2_extension)]:
59+
try:
60+
kwargs[name] = load_path_content(t_path, file_type=t_extension)
61+
except Exception as e:
62+
sys.exit(str(f"Error when loading {name}: {e}"))
6663

6764
if (t1_extension != t2_extension):
6865
if t1_extension in {'csv', 'tsv'}:
@@ -72,6 +69,6 @@ def diff(
7269

7370
try:
7471
diff = DeepDiff(**kwargs)
75-
except Exception as e:
76-
sys.exit(str(e))
72+
except Exception as e: # pragma: no cover. No need to test this.
73+
sys.exit(str(e)) # pragma: no cover. No need to test this.
7774
pprint(diff, indent=2)
Collapse file

‎deepdiff/serialization.py‎

Copy file name to clipboardExpand all lines: deepdiff/serialization.py
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
import collections # NOQA
1212
try:
1313
import yaml
14-
except ImportError:
15-
yaml = None
14+
except ImportError: # pragma: no cover.
15+
yaml = None # pragma: no cover.
1616
try:
1717
import toml
18-
except ImportError:
19-
toml = None
18+
except ImportError: # pragma: no cover.
19+
toml = None # pragma: no cover.
2020
try:
2121
import clevercsv
22-
except ImportError:
23-
clevercsv = None
22+
except ImportError: # pragma: no cover.
23+
clevercsv = None # pragma: no cover.
2424
from copy import deepcopy
2525
from collections.abc import Mapping
2626
from deepdiff.helper import (strings, json_convertor_default, get_type, TEXT_VIEW)
@@ -327,22 +327,22 @@ def load_path_content(path, file_type=None):
327327
with open(path, 'r') as the_file:
328328
content = json.load(the_file)
329329
elif file_type in {'yaml', '.yml'}:
330-
if yaml is None:
331-
raise ImportError('Pyyaml needs to be installed.')
330+
if yaml is None: # pragma: no cover.
331+
raise ImportError('Pyyaml needs to be installed.') # pragma: no cover.
332332
with open(path, 'r') as the_file:
333333
content = yaml.safe_load(the_file)
334334
elif file_type == 'toml':
335-
if toml is None:
336-
raise ImportError('Toml needs to be installed.')
335+
if toml is None: # pragma: no cover.
336+
raise ImportError('Toml needs to be installed.') # pragma: no cover.
337337
with open(path, 'r') as the_file:
338338
content = toml.load(the_file)
339339
elif file_type == 'pickle':
340340
with open(path, 'rb') as the_file:
341341
content = the_file.read()
342342
content = pickle_load(content)
343343
elif file_type in {'csv', 'tsv'}:
344-
if clevercsv is None:
345-
raise ImportError('CleverCSV needs to be installed.')
344+
if clevercsv is None: # pragma: no cover.
345+
raise ImportError('CleverCSV needs to be installed.') # pragma: no cover.
346346
content = clevercsv.wrappers.read_dicts(path)
347347
else:
348348
raise UnsupportedFormatErr('Only json, yaml, toml, csv, tsv and pickle are supported.')
Collapse file

‎tests/fixtures/t1_corrupt.json‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[{
2+
"key1": "value1",
3+
"key2": "value2",
4+
}]
Collapse file

‎tests/test_command.py‎

Copy file name to clipboardExpand all lines: tests/test_command.py
+17-9Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@
99
@pytest.mark.skipif(pypy3, reason='clevercsv is not supported in pypy3')
1010
class TestCommands:
1111

12-
@pytest.mark.parametrize('t1, t2, kwargs, expected_in_stdout', [
13-
('t1.json', 't2.json', {}, "'dictionary_item_added\': [root[0]"),
14-
('t1.json', 't2_json.csv', {}, "'old_value\': \'value2\'"),
15-
('t1.csv', 't2.csv', {}, "\'new_value\': \'James\'"),
16-
('t1.toml', 't2.toml', {}, "10.0.0.2"),
17-
('t1.pickle', 't2.pickle', {}, "'new_value': 5, 'old_value': 1"),
18-
('t1.yaml', 't2.yaml', {}, "'new_value': 61, 'old_value': 65"),
12+
@pytest.mark.parametrize('t1, t2, kwargs, expected_in_stdout, expected_exit_code', [
13+
('t1.json', 't2.json', {}, "'dictionary_item_added\': [root[0]", 0),
14+
('t1_corrupt.json', 't2.json', {}, "Expecting property name enclosed in double quotes", 1),
15+
('t1.json', 't2_json.csv', {}, "'old_value\': \'value2\'", 0),
16+
('t2_json.csv', 't1.json', {}, "'old_value\': \'value3\'", 0),
17+
('t1.csv', 't2.csv', {}, "\'new_value\': \'James\'", 0),
18+
('t1.toml', 't2.toml', {}, "10.0.0.2", 0),
19+
('t1.pickle', 't2.pickle', {}, "'new_value': 5, 'old_value': 1", 0),
20+
('t1.yaml', 't2.yaml', {}, "'new_value': 61, 'old_value': 65", 0),
1921
])
20-
def test_diff_command(self, t1, t2, kwargs, expected_in_stdout):
22+
def test_diff_command(self, t1, t2, kwargs, expected_in_stdout, expected_exit_code):
2123
t1 = os.path.join(FIXTURES_DIR, t1)
2224
t2 = os.path.join(FIXTURES_DIR, t2)
2325
runner = CliRunner()
2426
result = runner.invoke(diff, [t1, t2], **kwargs)
25-
assert result.exit_code == 0
27+
assert result.exit_code == expected_exit_code
2628
assert expected_in_stdout in result.output
29+
30+
def test_cli_cant_find_file(self):
31+
runner = CliRunner()
32+
result = runner.invoke(diff, ['phantom_file1', 'phantom_file2'])
33+
assert result.exit_code == 2
34+
assert "Path 'phantom_file1' does not exist" in result.output

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.