socallinuxexpo / scale-network

SCaLE's on-site expo network configurations, wifi, tooling, and scripts
https://www.socallinuxexpo.org/
BSD 3-Clause "New" or "Revised" License
40 stars 16 forks source link

[READY] add better datastore test clarity #657

Closed kylerisse closed 5 months ago

kylerisse commented 5 months ago

Fixes #480

Description of PR

Updates data validation to be more verbose.

Previous Behavior

New Behavior

Tests

Locally:

  1. Fix for issue 480, this is the new output of a field based validation with file name and function name added:
    
    > pytest -vv -p no:cacheprovider
    ================================================================================= test session starts =================================================================================
    platform darwin -- Python 3.11.3, pytest-7.1.3, pluggy-1.0.0 -- /nix/store/mcfk7g2qscks090ww00kzlxzqdk0z02x-python3-3.11.3/bin/python3.11
    rootdir: /Users/kyle.risse/go/src/github.com/kylerisse/scale-network/facts
    collected 5 items

test_datasources.py::test_aplist_csv FAILED [ 20%] test_datasources.py::test_pilist_csv PASSED [ 40%] test_datasources.py::test_routerlist_csv PASSED [ 60%] test_datasources.py::test_serverlist_csv PASSED [ 80%] test_datasources.py::test_switchtypes_tsv PASSED [100%]

====================================================================================== FAILURES ======================================================================================= _ test_aplistcsv

def test_aplist_csv():
    '''test aplist.csv'''
    meta = {
        "file": "./aps/aplist.csv",
        "header": True,
        "count": 10,
        "cols": [
            ds.isvalidhostname,
            ds.isuntested,
            ds.isvalidmac,
            ds.isvalidip,
            ds.isvalidwifi24chan,
            ds.isvalidwifi5chan,
            ds.isint,
            ds.isintorempty,
            ds.isintorempty,
            ds.isintorempty
        ]
    }
    result, err = ds.test_csvfile(meta)
  assert result, err

E AssertionError: invalid field 173 failed isvalidwifi5chan at line 1 of ./aps/aplist.csv E assert False

test_datasources.py:28: AssertionError =============================================================================== short test summary info =============================================================================== FAILED test_datasources.py::test_aplist_csv - AssertionError: invalid field 173 failed isvalidwifi5chan at line 1 of ./aps/aplist.csv ============================================================================= 1 failed, 4 passed in 0.02s =============================================================================



Untested: Running test via flake, I'm on Darwin 🤦‍♂️ 
kylerisse commented 5 months ago

@sarcasticadmin I'm happy with this and can mark as ready. I left as WIP in case you want to pull it down and test via nix build -L .#checks.x86_64-linux.pytest-facts just in case there is some kind of versioning issue that I can't recreate. Also, let me know if this output is what you're looking for. All I did was leverage python's __name__ since our validation functions are pretty well named already and keeps things simple.