source.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright 2018 Matt Martz
  4. # All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License. You may obtain
  8. # a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. import sys
  18. import subprocess
  19. cmd = [sys.executable, 'speedtest.py', '--source', '127.0.0.1']
  20. p = subprocess.Popen(
  21. cmd,
  22. stdout=subprocess.PIPE,
  23. stderr=subprocess.PIPE
  24. )
  25. stdout, stderr = p.communicate()
  26. if p.returncode != 1:
  27. raise SystemExit('%s did not fail with exit code 1' % ' '.join(cmd))
  28. if 'Invalid argument'.encode() not in stderr:
  29. raise SystemExit(
  30. '"Invalid argument" not found in stderr:\n%s' % stderr.decode()
  31. )