1 # Black box tests for script/traffic_leaner
3 # Copyright (C) Catalyst IT Ltd. 2017
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Blackbox tests for traffic_summary"""
20 from contextlib import contextmanager
25 from samba.tests import BlackboxTestCase
27 SCRIPT = "script/traffic_summary.pl"
28 DATA_DIR = "python/samba/tests/blackbox/testdata"
29 INPUT = os.path.join(DATA_DIR, "traffic_summary.pdml")
30 EXPECTED_FN = os.path.join(DATA_DIR, "traffic_summary.expected")
34 def temp_file(temp_dir):
36 tf = tempfile.NamedTemporaryFile(dir=temp_dir)
41 if os.path.exists(name):
45 class TrafficSummaryTests(BlackboxTestCase):
48 """Check that perl XML::Twig module is installed.
49 Traffic summary depends on this module being installed.
51 line = "perl -MXML::Twig -e 1"
52 p = subprocess.Popen(line, shell=True)
56 def test_traffic_summary(self):
57 if not self.check_twig():
58 self.skipTest("Perl module XML::Twig is not installed")
60 with temp_file(self.tempdir) as output:
61 command = "%s %s >%s" % (SCRIPT, INPUT, output)
63 self.check_run(command)
64 expected = open(EXPECTED_FN).readlines()
65 actual = open(output).readlines()
66 self.assertEquals(expected, actual)