Skip to content

Commit e47a5df

Browse files
authored
Merge pull request #75 from dwight525/patch-2
Update usage.md
2 parents bc05a15 + 26fcaa4 commit e47a5df

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

docs/usage.md

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ It's worth pointing out that `jdiff` is focused on the comparison of the two obj
1111

1212
## exact_match
1313

14-
Check type `exact_match` is concerned with the value of the elements within the data structure. The key-value pairs should match between the reference and comparison data. A diff is generated between the two data sets and tested to see if all the keys and values match.
14+
Check type `exact_match` is concerned with the value of the elements within the data structure. The key-value pairs should match between the reference and comparison data. A diff is generated between the two data sets and tested to see whether all the keys and values match.
1515

16-
As some outputs might be too verbose or include fields that constantly change (e.g. interface counter), it is possible to exclude a portion of data traversed by JMESPath by defining a keys exclusion list.
16+
As some outputs might be too verbose or include fields that constantly change (e.g., interface counter), it is possible to exclude a portion of data traversed by JMESPath by defining a key's exclusion list.
1717

1818

1919
Examples:
@@ -102,9 +102,9 @@ Use the evaluate method to return the result.
102102
False)
103103
```
104104

105-
As we can see, we return a tuple containing a diff between the pre and post data as well as a boolean for the overall test result. In this case a difference has been found so the status of the test is `False`.
105+
As we can see, we return a tuple containing a diff between the pre and post data as well as a boolean for the overall test result. In this case a difference has been found, so the status of the test is `False`.
106106

107-
Let's see a better way to run `exact_match` for this specific case. Because there is a lot of extra key value pairs, some of which change all the time, we are only interested in `interfaceStatus`, so we can use a utility of jdiff: `extract_data_from_json`, which can extract the value from the keys we are interested in and discard the rest.
107+
Let's see a better way to run `exact_match` for this specific case. Because there are a lot of extra key value pairs, some of which change all the time, we are interested only in `interfaceStatus`. So we can use a utility of jdiff: `extract_data_from_json`, which can extract the value from the keys we are interested in and discard the rest.
108108

109109
```python
110110
>>> my_jmspath = "result[*].interfaces.*.[$name$,interfaceStatus]"
@@ -121,13 +121,13 @@ Let's see a better way to run `exact_match` for this specific case. Because ther
121121
False)
122122
```
123123

124-
In this case, we only want to compare the value of a single key, the `interfaceStatus` key, so we define the jmespath logic to take the name and the interfaceStatus values from the all the interface objects in the data object.
124+
In this case, we only want to compare the value of a single key, the `interfaceStatus` key. So we define the JMESPath logic to take the name and the interfaceStatus values from all the interface objects in the data object.
125125

126-
This type of logic to extract keys and value from the object is called anchor logic and more [here](#extra_value_from_json).
126+
This type of logic to extract keys and value from the object is called anchor logic. Find more about anchor logic [here](#extra_value_from_json).
127127

128128
### Tolerance
129129

130-
The `tolerance` test checks for the deviation between the value or count between the reference and comparison values. A `tolerance` is defined and passed to the check along with the comparison and reference values.
130+
The `tolerance` test checks for the deviation between the value or count of the reference and comparison values. A `tolerance` is defined and passed to the check along with the comparison and reference values.
131131

132132
The `tolerance` argument must be a `float > 0`. The calculation is percentage based, and the test of the values may be +/- the `tolerance` percentage.
133133

@@ -190,7 +190,7 @@ Let's have a look at a couple of examples:
190190
... }
191191
>>> my_check = CheckType.create("tolerance")
192192
```
193-
We will define a jmespath search for the values we want to test and extract from the reference and comparison objects.
193+
We will define a JMESPath search for the values we want to test and extract from the reference and comparison objects.
194194
```python
195195
>>> my_jmspath = "global.$peers$.*.*.ipv4.[accepted_prefixes,received_prefixes,sent_prefixes]"
196196
>>> reference_value = extract_data_from_json(reference_data, my_jmspath)
@@ -231,13 +231,13 @@ Let's increase the tolerance:
231231
({}, True)
232232
```
233233

234-
This check can test if the difference between two values is within a specified tolerance percentage. It could be useful in cases where values like route metrics or optical power levels fluctuate by a small amount. It might be desirable to treat these values as equal if the deviation is within a given range. You can pass in the result of len() to count the number of objects returned within your data.
234+
This check can test whether the difference between two values is within a specified tolerance percentage. It could be useful in cases where values like route metrics or optical power levels fluctuate by a small amount. It might be desirable to treat these values as equal if the deviation is within a given range. You can pass in the result of len() to count the number of objects returned within your data.
235235

236-
### Parameter match
236+
### Parameter Match
237237

238238
The `parameter_match` check provides a way to test key/value pairs against baseline values.
239239

240-
The check defines baseline key/value pairs in a Python dictionary. Additionally, mode is set to one of `match` or `no-match`, which specifies if the data should match the baseline, or not.
240+
The check defines baseline key/value pairs in a Python dictionary. Additionally, mode is set to one of `match` or `no-match`, which specifies whether the data should match the baseline, or not.
241241

242242
The test fails if:
243243

@@ -282,7 +282,7 @@ For example, in network data:
282282
>>> comparison_value = extract_data_from_json(comparison_data, path=my_jmspath)
283283
```
284284

285-
This test requires a mode argument, match in this case matches the keys and values in the "params" to the keys and values in the data.
285+
This test requires a mode argument; match in this case matches the keys and values in the "params" to the keys and values in the data.
286286
```python
287287
>>> actual_results = my_check.evaluate(
288288
post_value,
@@ -296,7 +296,7 @@ This test requires a mode argument, match in this case matches the keys and valu
296296
({'Management1': {'interfaceStatus': 'down'}}, False)
297297
```
298298

299-
mode: no-match - return the keys and values from the test object that do not match the keys and values provides in "params"
299+
mode: no-match - return the keys and values from the test object that do not match the keys and values provided in "params"
300300
```python
301301
>>> my_parameter_match =
302302
>>> actual_results = my_check.evaluate(
@@ -315,7 +315,7 @@ mode: no-match - return the keys and values from the test object that do not mat
315315

316316
The `regex` check type evaluates data against a regular expression passed as an argument to the `evaluate` method. Similarly to `parameter_match` check, the `match` and `no-match` modes are supported.
317317

318-
Let's run an example where we want to check the `burnedInAddress` key has a string representing a MAC Address as value
318+
Let's run an example where we want to check the `burnedInAddress` key has a string representing a MAC address as value.
319319

320320
```python
321321
>>> data = {
@@ -344,21 +344,21 @@ Let's run an example where we want to check the `burnedInAddress` key has a stri
344344
... }
345345
... ]
346346
... }
347-
>>> # Python regex for matching MAC Address string
347+
>>> # Python regex for matching MAC address string
348348
>>> regex_args = {"regex": "(?:[0-9a-fA-F]:?){12}", "mode": "match"}
349349
>>> path = "result[*].interfaces.*.[$name$,burnedInAddress]"
350350
>>> check = CheckType.create(check_type="regex")
351351
>>> value = check.extract_data_from_json(output=data, path=path)
352352
>>> value
353353
[{'Management1': {'burnedInAddress': '08:00:27:e6:b2:f8'}}]
354354
>>> result = check.evaluate(value, **regex_args)
355-
>>> # The test is passed as the burnedInAddress value match our regex
355+
>>> # The test is passed as the burnedInAddress value matches our regex
356356
>>> result
357357
({}, True)
358358
>>> # What if we want "no-match"?
359359
>>> regex_args = {"regex": "(?:[0-9a-fA-F]:?){12}", "mode": "no-match"}
360360
>>> result = check.evaluate(value, **regex_args)
361-
>>> # jdiff return the failing data as the regex match the value
361+
>>> # jdiff returns the failing data, as the regex matches the value
362362
>>> result
363363
({'Management1': {'burnedInAddress': '08:00:27:e6:b2:f8'}}, False)
364364
```
@@ -371,7 +371,7 @@ The `operator` check is a collection of more specific checks divided into catego
371371

372372
| Przemek: The below is not very readable? Indented sections are rendered as code blocks. I would suggest naming these groups "categories" or "groups" and explaing that each of the names is the name of the check that needs to be passed as the argument.
373373

374-
#### `in` operators
374+
#### `in` Operators
375375

376376

377377
1. is-in: Check if the specified element string value is included in a given list of strings.
@@ -386,35 +386,37 @@ The `operator` check is a collection of more specific checks divided into catego
386386
- in-range: [20, 70]
387387
check if value is in range between 20 and 70
388388

389+
|Dwight: delete the space between 5 and comma in #4, below?
390+
389391
4. not-range: Check if the value of a specified element is outside of a given numeric range.
390392
- not-range: [5 , 40]
391393
checks if value is not in range between 5 and 40
392394

393-
#### `bool` operators
395+
#### `bool` Operators
394396

395397
1. all-same: Check if all content values for the specified element are the same. It can also be used to compare all content values against another specified element.
396398
- all-same: flap-count
397-
checks if all values of node <flap-count> in given path is same or not.
399+
checks if all values of node <flap-count> in given path are same or not.
398400

399-
#### `str` operators
401+
#### `str` Operators
400402

401-
1. contains: determines if an element string value contains the provided test-string value.
403+
1. contains: Determines if an element string value contains the provided test-string value.
402404
- contains: "underlay"
403405
checks if "underlay" is present in given data or not.
404406

405-
2. not-contains: determines if an element string value does not contain the provided test-string value.
407+
2. not-contains: Determines if an element string value does not contain the provided test-string value.
406408
- not-contains: "overlay"
407409
checks if "overlay" is present in given node or not.
408410

409-
#### `int`, `float` operators
411+
#### `int`, `float` Operators
410412

411413
1. is-gt: Check if the value of a specified element is greater than a given numeric value.
412414
- is-gt: 2
413-
checks if value should be greater than 2
415+
checks if value is greater than 2
414416

415417
2. is-lt: Check if the value of a specified element is lesser than a given numeric value.
416418
- is-lt: 55
417-
checks if value is lower than 55 or not.
419+
checks if value is less than 55
418420

419421

420422
Examples:
@@ -473,15 +475,15 @@ Examples:
473475
... ]
474476
... }
475477
>>> path = "result[0].vrfs.default.peerList[*].[$peerAddress$,peerGroup,vrf,state]"
476-
>>> # "operator" checks requires "mode" argument - which specify the operator logic to apply -
478+
>>> # "operator" checks require "mode" argument - which specifies the operator logic to apply -
477479
>>> # and "operator_data" required for the mode defined.
478480
>>> check_args = {"params": {"mode": "all-same", "operator_data": True}}
479481
>>> check = CheckType.create("operator")
480482
>>> value = check.extract_data_from_json(data, path)
481483
>>> value
482484
[{'7.7.7.7': {'peerGroup': 'EVPN-OVERLAY-SPINE', 'vrf': 'default', 'state': 'Connected'}}, {'10.1.0.0': {'peerGroup': 'IPv4-UNDERLAY-SPINE', 'vrf': 'default', 'state': 'Idle'}}]
483485
>>> result = check.evaluate(value, check_args)
484-
>>> # We are looking for peers that have the same peerGroup,vrf and state. If not, return those are not.
486+
>>> # We are looking for peers that have the same peerGroup, vrf, and state. If not, return those that do not.
485487
>>> result
486488
((False, [{'7.7.7.7': {'peerGroup': 'EVPN-OVERLAY-SPINE', 'vrf': 'default', 'state': 'Connected'}}, {'10.1.0.0': {'peerGroup': 'IPv4-UNDERLAY-SPINE', 'vrf': 'default', 'state': 'Idle'}}]), False)
487489
```
@@ -513,7 +515,7 @@ What about `str` operator?
513515
((True, [{'7.7.7.7': {'peerGroup': 'EVPN-OVERLAY-SPINE'}}]), False)
514516
```
515517

516-
Can you guess what would ne the outcome for an `int`, `float` operator?
518+
Can you guess what would be the outcome for an `int`, `float` operator?
517519

518520
```python
519521
>>> path = "result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]"

0 commit comments

Comments
 (0)