/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2019-08-24 14:43:51 UTC
  • Revision ID: teddy@recompile.se-20190824144351-2y0l31jpj496vrtu
Server: Add scaffolding for tests

* mandos: Add code to run tests via the unittest module, similar to
          the code in mandos-ctl.  Also shut down logging on exit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
# -*- mode: python; coding: utf-8 -*-
 
2
# -*- mode: python; after-save-hook: (lambda () (let ((command (if (fboundp 'file-local-name) (file-local-name (buffer-file-name)) (or (file-remote-p (buffer-file-name) 'localname) (buffer-file-name))))) (if (= (progn (if (get-buffer "*Test*") (kill-buffer "*Test*")) (process-file-shell-command (format "%s --check" (shell-quote-argument command)) nil "*Test*")) 0) (let ((w (get-buffer-window "*Test*"))) (if w (delete-window w))) (progn (with-current-buffer "*Test*" (compilation-mode)) (display-buffer "*Test*" '(display-buffer-in-side-window)))))); coding: utf-8 -*-
3
3
#
4
4
# Mandos server - give out binary blobs to connecting clients.
5
5
#
77
77
import itertools
78
78
import collections
79
79
import codecs
 
80
import unittest
80
81
 
81
82
import dbus
82
83
import dbus.service
2975
2976
 
2976
2977
    options = parser.parse_args()
2977
2978
 
2978
 
    if options.check:
2979
 
        import doctest
2980
 
        fail_count, test_count = doctest.testmod()
2981
 
        sys.exit(os.EX_OK if fail_count == 0 else 1)
2982
 
 
2983
2979
    # Default values for config file for server-global settings
2984
2980
    if gnutls.has_rawpk:
2985
2981
        priority = ("SECURE128:!CTYPE-X.509:+CTYPE-RAWPK:!RSA"
3619
3615
    # Must run before the D-Bus bus name gets deregistered
3620
3616
    cleanup()
3621
3617
 
 
3618
 
 
3619
def should_only_run_tests():
 
3620
    parser = argparse.ArgumentParser(add_help=False)
 
3621
    parser.add_argument("--check", action='store_true')
 
3622
    args, unknown_args = parser.parse_known_args()
 
3623
    run_tests = args.check
 
3624
    if run_tests:
 
3625
        # Remove --check argument from sys.argv
 
3626
        sys.argv[1:] = unknown_args
 
3627
    return run_tests
 
3628
 
 
3629
# Add all tests from doctest strings
 
3630
def load_tests(loader, tests, none):
 
3631
    import doctest
 
3632
    tests.addTests(doctest.DocTestSuite())
 
3633
    return tests
3622
3634
 
3623
3635
if __name__ == '__main__':
3624
 
    main()
 
3636
    try:
 
3637
        if should_only_run_tests():
 
3638
            # Call using ./mandos --check [--verbose]
 
3639
            unittest.main()
 
3640
        else:
 
3641
            main()
 
3642
    finally:
 
3643
        logging.shutdown()