/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-17 18:17:02 UTC
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190317181702-tf6uvnb0gnyw9z8v
mandos-ctl: Refactor tests

* mandos-ctl (Test_check_option_syntax.redirect_stderr_to_devnull):
  Override file objects instead of raw file descriptors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
962
962
    @staticmethod
963
963
    @contextlib.contextmanager
964
964
    def redirect_stderr_to_devnull():
965
 
        null = os.open(os.path.devnull, os.O_RDWR)
966
 
        stderrcopy = os.dup(sys.stderr.fileno())
967
 
        os.dup2(null, sys.stderr.fileno())
968
 
        os.close(null)
969
 
        try:
970
 
            yield
971
 
        finally:
972
 
            # restore stderr
973
 
            os.dup2(stderrcopy, sys.stderr.fileno())
974
 
            os.close(stderrcopy)
 
965
        old_stderr = sys.stderr
 
966
        with contextlib.closing(open(os.devnull, "w")) as null:
 
967
            sys.stderr = null
 
968
            try:
 
969
                yield
 
970
            finally:
 
971
                sys.stderr = old_stderr
975
972
 
976
973
    def check_option_syntax(self, options):
977
974
        check_option_syntax(self.parser, options)