Skip to content

Commit c24ee50

Browse files
authored
Merge pull request #2190 from strictdoc-project/stanislaw/code_climate
Code climate: backend/sdoc/writer: remove unused code
2 parents bb68975 + e767011 commit c24ee50

File tree

6 files changed

+20
-53
lines changed

6 files changed

+20
-53
lines changed

strictdoc/backend/sdoc/writer.py

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# mypy: disable-error-code="arg-type,attr-defined,no-untyped-call,no-untyped-def,union-attr,type-arg"
22
import os.path
3-
from enum import Enum
43
from pathlib import Path
54
from typing import Dict, List, Tuple, Union
65

@@ -24,7 +23,6 @@
2423
)
2524
from strictdoc.backend.sdoc.models.section import SDocSection
2625
from strictdoc.backend.sdoc.models.type_system import (
27-
FileEntry,
2826
GrammarElementFieldMultipleChoice,
2927
GrammarElementFieldSingleChoice,
3028
GrammarElementFieldString,
@@ -38,12 +36,6 @@
3836
from strictdoc.helpers.string import ensure_newline
3937

4038

41-
class TAG(Enum):
42-
SECTION = 1
43-
REQUIREMENT = 2
44-
COMPOSITE_REQUIREMENT = 3
45-
46-
4739
class SDWriter:
4840
def __init__(self, project_config: ProjectConfig):
4941
self.project_config: ProjectConfig = project_config
@@ -405,39 +397,24 @@ def _print_requirement_fields(
405397
fields = section_content.ordered_fields_lookup[field_name]
406398
for field in fields:
407399
field_value = field.get_text_value()
400+
assert len(field_value) > 0
401+
408402
if field.is_multiline():
409403
output += f"{field_name}: >>>"
410404
output += "\n"
411-
if len(field_value) > 0:
412-
if field_value != "\n":
413-
output += ensure_newline(field_value)
405+
if field_value != "\n":
406+
output += ensure_newline(field_value)
414407
output += "<<<"
415408
output += "\n"
416409
else:
417-
if len(field_value) > 0:
418-
output += f"{field_name}: "
419-
output += field_value
420-
else:
421-
output += f"{field_name}:"
410+
output += f"{field_name}: "
411+
output += field_value
422412
output += "\n"
423413

424414
output += SDWriter._print_requirement_relations(section_content)
425415

426416
return output
427417

428-
@staticmethod
429-
def _print_closing_tag(closing_tag):
430-
output = ""
431-
if closing_tag == TAG.SECTION:
432-
output += "\n"
433-
output += "[/SECTION]"
434-
output += "\n"
435-
if closing_tag == TAG.COMPOSITE_REQUIREMENT:
436-
output += "\n"
437-
output += "[/COMPOSITE_REQUIREMENT]"
438-
output += "\n"
439-
return output
440-
441418
@staticmethod
442419
def _print_grammar_field_type(grammar_field):
443420
output = ""
@@ -465,31 +442,14 @@ def _print_grammar_field_type(grammar_field):
465442
elif isinstance(grammar_field, GrammarElementFieldTag):
466443
output += RequirementFieldType.TAG
467444
else:
468-
raise NotImplementedError from None
445+
raise NotImplementedError from None # pragma: no cover
469446

470447
output += "\n"
471448
output += " REQUIRED: "
472449
output += "True" if grammar_field.required else "False"
473450
output += "\n"
474451
return output
475452

476-
@staticmethod
477-
def _print_file_entry(row_separator, file_entry: FileEntry) -> str:
478-
output = ""
479-
if row_separator:
480-
output += "- "
481-
else:
482-
output += " "
483-
if file_entry.g_file_format:
484-
output += "FORMAT: "
485-
output += file_entry.g_file_format
486-
output += "\n "
487-
output += "VALUE: "
488-
output += file_entry.g_file_path
489-
output += "\n"
490-
491-
return output
492-
493453
@classmethod
494454
def _print_requirement_relations(cls, requirement: SDocNode):
495455
assert isinstance(requirement, SDocNode)
@@ -541,5 +501,5 @@ def _print_requirement_relations(cls, requirement: SDocNode):
541501
output += child_reference.role
542502
output += "\n"
543503
else:
544-
raise AssertionError("Must not reach here.")
504+
raise AssertionError("Must not reach here.") # pragma: no cover
545505
return output

strictdoc/core/project_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def load_from_path_or_get_default(
370370
f"{exception}."
371371
) from None
372372
except Exception as exception:
373-
raise NotImplementedError from exception
373+
raise NotImplementedError from exception # pragma: no cover
374374

375375
config_last_update = get_file_modification_time(path_to_config)
376376

strictdoc/export/json/json_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _write_requirement_relations(node: SDocNode) -> List:
345345
if child_reference.role is not None:
346346
relation_dict["ROLE"] = child_reference.role
347347
else:
348-
raise AssertionError("Must not reach here.")
348+
raise AssertionError("Must not reach here.") # pragma: no cover
349349

350350
relations_list.append(relation_dict)
351351

strictdoc/git/change.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(
104104
assert lhs_section is None, lhs_section
105105
change_type = ChangeType.SECTION_ADDED
106106
else:
107-
raise AssertionError("Must not reach here.")
107+
raise AssertionError("Must not reach here.") # pragma: no cover
108108
self.change_type = change_type
109109

110110
def is_paired_change(self) -> bool:
@@ -186,7 +186,7 @@ def __init__(
186186
elif rhs_requirement is not None:
187187
change_type = ChangeType.REQUIREMENT_ADDED
188188
else:
189-
raise AssertionError("Must not reach here.")
189+
raise AssertionError("Must not reach here.") # pragma: no cover
190190
self.change_type = change_type
191191

192192
def is_paired_change(self) -> bool:

strictdoc/helpers/form_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _set_value_by_key_path(obj, parts, value):
4545
assert isinstance(cursor, dict)
4646
cursor[part] = value
4747
else:
48-
raise NotImplementedError from None
48+
raise NotImplementedError from None # pragma: no cover
4949

5050

5151
FIELD_NAME = "[A-Za-z0-9_]*"

tasks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ def coverage_combine(context):
473473
build/coverage/unit_server/.coverage
474474
""",
475475
)
476+
run_invoke_with_tox(
477+
context,
478+
ToxEnvironment.CHECK,
479+
"""
480+
coverage html --data-file build/coverage/.coverage.combined
481+
""",
482+
)
476483

477484

478485
@task

0 commit comments

Comments
 (0)