# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""
test_dstatplugins
----------------------------------

Tests for `dstat_plugins` module.
"""

import os
import subprocess
import tempfile
import time

from dstat_plugins.tests import base


class TestDstatplugins(base.TestCase):

    def test_mysql_innodb(self):
        tfd, tfpath = tempfile.mkstemp()
        d = subprocess.Popen(['dstat', '--debug', '--debug', '-c',
                              '--output', tfpath, '--nocolor',
                              '--mysql5-innodb', '1', '1'])
        time.sleep(1)
        d.terminate()
        result = d.wait()
        self.assertEqual(-15, result)
        csv = os.fdopen(tfd).read()
        self.assertIn('--mysql5-innodb', csv)

@@ -809,48 +809,65 @@
 def 
-test_mysql_innodb(self):%0A        tfd, tf
+_run_plugin(self, args):%0A        self.temp_fd, self.temp_
 path
@@ -1001,27 +1001,22 @@
 t', 
-tfpath, '--nocolor'
+self.temp_path
 ,%0A  
@@ -1050,33 +1050,24 @@
  '--
-mysql5-innodb', '1', '1'%5D
+nocolor'%5D + args
 )%0A  
@@ -1122,14 +1122,12 @@
   re
-sult =
+turn
  d.w
@@ -1136,44 +1136,119 @@
 t()%0A
-        self.assertEqual(-15, result
+%0A    def test_mysql_innodb(self):%0A        self.assertEqual(-15, self._run_plugin(%5B'--mysql5-innodb', '1', '1'%5D)
 )%0A  
@@ -1269,17 +1269,26 @@
 .fdopen(
-t
+self.temp_
 fd).read

Refactor test runner