'Check that warnings argument of TextTestRunner correctly affects the
behavior of the warnings.'

def test_warnings(self):

    def get_parse_out_err(p):
        return [b.splitlines() for b in p.communicate()]
    opts = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=os.path.dirname(__file__))
    ae_msg = 'Please    use    assertEqual    instead.'
    at_msg = 'Please    use    assertTrue    instead.'
    p = subprocess.Popen([sys.executable, '_test_warnings.py'], **opts)
    (out, err) = get_parse_out_err(p)
    self.assertIn('OK', err)
    self.assertEqual(len(out), 12)
    for msg in ['dw', 'iw', 'uw']:
        self.assertEqual(out.count(msg), 3)
    for msg in [ae_msg, at_msg, 'rw']:
        self.assertEqual(out.count(msg), 1)
    args_list = ([sys.executable, '_test_warnings.py', 'ignore'], [sys.executable, '-Wa', '_test_warnings.py', 'ignore'], [sys.executable, '-Wi', '_test_warnings.py'])
    for args in args_list:
        p = subprocess.Popen(args, **opts)
        (out, err) = get_parse_out_err(p)
        self.assertIn('OK', err)
        self.assertEqual(len(out), 0)
    p = subprocess.Popen([sys.executable, '_test_warnings.py', 'always'], **opts)
    (out, err) = get_parse_out_err(p)
    self.assertIn('OK', err)
    self.assertEqual(len(out), 14)
    for msg in ['dw', 'iw', 'uw', 'rw']:
        self.assertEqual(out.count(msg), 3)
    for msg in [ae_msg, at_msg]:
        self.assertEqual(out.count(msg), 1)
