| Conditions | 1 |
| Total Lines | 76 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Copyright 2024, Red Hat, Inc. |
||
| 13 | @pytest.fixture(name="parser") |
||
| 14 | def fixture_parser(): |
||
| 15 | sc_ns = NAMESPACES["oval-characteristics"] |
||
| 16 | is_ns = NAMESPACES["ind-sys"] |
||
| 17 | |||
| 18 | o1_id = "oval:example:obj:1" |
||
| 19 | o2_id = "oval:example:obj:2" |
||
| 20 | o3_id = "oval:example:obj:3" |
||
| 21 | i1_id = "11117777" |
||
| 22 | i2_id = "11117777" |
||
| 23 | i3_id = "33339999" |
||
| 24 | |||
| 25 | o1 = etree.Element( |
||
| 26 | "{%s}object" % sc_ns, nsmap=NAMESPACES, id=o1_id, version="1", |
||
| 27 | flag="complete") |
||
| 28 | o1_r1 = etree.Element( |
||
| 29 | "{%s}reference" % sc_ns, nsmap=NAMESPACES, item_ref=i1_id) |
||
| 30 | o1.append(o1_r1) |
||
| 31 | |||
| 32 | o2 = etree.Element( |
||
| 33 | "{%s}object" % sc_ns, nsmap=NAMESPACES, id=o2_id, version="1", |
||
| 34 | flag="complete") |
||
| 35 | o2_r1 = etree.Element( |
||
| 36 | "{%s}reference" % sc_ns, nsmap=NAMESPACES, item_ref=i2_id) |
||
| 37 | o2.append(o2_r1) |
||
| 38 | o2_r2 = etree.Element( |
||
| 39 | "{%s}reference" % sc_ns, nsmap=NAMESPACES, item_ref=i3_id) |
||
| 40 | o2.append(o2_r2) |
||
| 41 | |||
| 42 | o3 = etree.Element( |
||
| 43 | "{%s}object" % sc_ns, nsmap=NAMESPACES, id=o3_id, version="1", |
||
| 44 | flag="does not exist") |
||
| 45 | |||
| 46 | collected_objects = { |
||
| 47 | o1_id: o1, |
||
| 48 | o2_id: o2, |
||
| 49 | o3_id: o3 |
||
| 50 | } |
||
| 51 | |||
| 52 | i1 = etree.Element( |
||
| 53 | "{%s}textfilecontent_item" % is_ns, nsmap=NAMESPACES, id=i1_id, |
||
| 54 | status="exists") |
||
| 55 | i1_filepath = etree.Element("{%s}filepath" % is_ns, nsmap=NAMESPACES) |
||
| 56 | i1_filepath.text = "/var/cities" |
||
| 57 | i1.append(i1_filepath) |
||
| 58 | i1_text = etree.Element("{%s}text" % is_ns, nsmap=NAMESPACES) |
||
| 59 | i1_text.text = "Paris" |
||
| 60 | i1.append(i1_text) |
||
| 61 | |||
| 62 | i2 = etree.Element( |
||
| 63 | "{%s}textfilecontent_item" % is_ns, nsmap=NAMESPACES, id=i2_id, |
||
| 64 | status="exists") |
||
| 65 | i2_filepath = etree.Element("{%s}filepath" % is_ns, nsmap=NAMESPACES) |
||
| 66 | i2_filepath.text = "/var/cities" |
||
| 67 | i2.append(i2_filepath) |
||
| 68 | i2_text = etree.Element("{%s}text" % is_ns, nsmap=NAMESPACES) |
||
| 69 | i2_text.text = "London" |
||
| 70 | i2.append(i2_text) |
||
| 71 | |||
| 72 | i3 = etree.Element( |
||
| 73 | "{%s}textfilecontent_item" % is_ns, nsmap=NAMESPACES, id=i3_id, |
||
| 74 | status="exists") |
||
| 75 | i3_filepath = etree.Element("{%s}filepath" % is_ns, nsmap=NAMESPACES) |
||
| 76 | i3_filepath.text = "/var/cities" |
||
| 77 | i3.append(i3_filepath) |
||
| 78 | i3_text = etree.Element("{%s}text" % is_ns, nsmap=NAMESPACES) |
||
| 79 | i3_text.text = "Prague" |
||
| 80 | i3.append(i3_text) |
||
| 81 | |||
| 82 | system_data = { |
||
| 83 | i1_id: i1, |
||
| 84 | i2_id: i2, |
||
| 85 | i3_id: i3, |
||
| 86 | } |
||
| 87 | |||
| 88 | return OVALItemsParser(collected_objects, system_data) |
||
| 89 | |||
| 120 |