Skip to content

Commit

Permalink
chg: usr: refactor for testing, cleanup script imports and test data
Browse files Browse the repository at this point in the history
* add some new control data files for test support

Signed-off-by: Stephen L Arnold <nerdboy@gentoo.org>
  • Loading branch information
sarnold committed Jun 8, 2024
1 parent 3da7d2f commit fa17ceb
Show file tree
Hide file tree
Showing 8 changed files with 1,445 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pre-commit install
# To update the pre-commit hooks run:
# pre-commit install-hooks
exclude: '^(.tox/|docs/|^setup.py$)'
exclude: '^(.tox/|docs/|^setup.py$|^tests/data/controls.csv$)'
repos:
- repo: meta
hooks:
Expand Down
5 changes: 3 additions & 2 deletions scripts/csvchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
Simple consumer test.
"""

from ymltoxml.utils import text_data_writer, text_file_reader
from yaml_tools.utils import text_data_writer, text_file_reader

OPTS = {
'file_encoding': 'utf-8',
'output_format': 'csv',
'default_csv_hdr': None,
}


# read in some json "column data"
data = text_file_reader('tests/data/catalog.json', OPTS)
data = text_file_reader('tests/data/controls.yml', OPTS)
# spit out CSV records
ret = text_data_writer(data, OPTS)
4 changes: 2 additions & 2 deletions scripts/xform_idchk.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from natsort import os_sorted

from ymltoxml.templates import xform_id
from ymltoxml.utils import text_file_reader
from yaml_tools.templates import xform_id
from yaml_tools.utils import text_file_reader

OPTS = {
'file_encoding': 'utf-8',
Expand Down
30 changes: 21 additions & 9 deletions src/yaml_tools/oscal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,30 @@ def csv_append_id_data(in_ids, prog_opts, uargs): # pragma: no cover
writer.writerow(headers)

for ctl in reader:
ctl_id = xform_id(ctl[0])
sub_ids = [s for s in in_ids if ctl_id in s]
if ctl_id in in_ids:
ctl.append('Y')
elif sub_ids != []:
ctl.append(sub_ids[0])
else:
ctl.append('N')
ctl.append(ctl_id)
ctl = csv_row_match(in_ids, ctl)
writer.writerow(ctl)


def csv_row_match(in_ids, ctl):
"""
Extracted ctl munging from ``csv_append_id_data`` loop for testing.
:param: ctl
:type ctl: csv row data
:return ctl: munged ctl
"""
ctl_id = xform_id(ctl[0])
sub_ids = [s for s in in_ids if ctl_id in s]
if ctl_id in in_ids:
ctl.append('Y')
elif sub_ids != []:
ctl.append(sub_ids[0])
else:
ctl.append('N')
ctl.append(ctl_id)
return ctl


def load_input_data(filepath, prog_opts, use_ssg=False, debug=False):
"""
Find and gather the inputs, ie, content file(s) and user control IDs,
Expand Down
6 changes: 3 additions & 3 deletions tests/data/OE-expanded-profile-all-ids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AC-23
AC-3
AC-3(3)(a)
AC-3(4)
AC-3.1
AC-3(1)
AC-4
AC-6
AC-6 (1)
Expand Down Expand Up @@ -53,7 +53,7 @@ AU-2
AU-2(a)
AU-2(d)
AU-3
AU-3.1
AU-3(1)
AU-4
AU-4(1)
AU-5(1)
Expand Down Expand Up @@ -133,7 +133,7 @@ IA-5(f)
IA-5(h)
IA-5(v)
IA-7
IA-7.1
IA-7(1)
IR-5(1)
MA-3
MA-4(1)(a)
Expand Down
428 changes: 428 additions & 0 deletions tests/data/controls.csv

Large diffs are not rendered by default.

Loading

0 comments on commit fa17ceb

Please sign in to comment.