File: test_config_parser.py

package info (click to toggle)
apt-forktracer 0.11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 384 kB
  • sloc: python: 1,995; makefile: 16
file content (51 lines) | stat: -rwxr-xr-x 2,151 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
# apt-forktracer - a utility for managing package versions
# Copyright (C) 2008,2010,2019 Marcin Owsiany <porridge@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from mox3 import mox as mox
import unittest

from apt_forktracer.testlib import test_helper
from apt_forktracer.config_parser import ConfigParser
from apt_forktracer.config import Config

class Test_ConfigParser(test_helper.MoxTestCase):
	def setUp(self):
		super(Test_ConfigParser, self).setUp()
		self.cp = ConfigParser()
		self.c = self.mox.CreateMock(Config)
	def test_loading_empty_file(self):
		self.mox.ReplayAll()
		self.assertEqual(self.cp.load([], self.c), [])
	def test_loading_invalid_syntax_file(self):
		fake_file = ['\n', 'invalid line\n']
		self.mox.ReplayAll()
		self.assertRaisesWithMessageContaining(Exception, 'line 2', self.cp.load, fake_file)
	def test_loading_invalid_stanza_file(self):
		fake_file = ['\n', 'package:val\n', 'acCepT-OrigiN: val2\n']
		self.mox.ReplayAll()
		self.assertRaisesWithMessageContaining(Exception, 'line 3', self.cp.load, fake_file)
	def test_loading_valid_file(self):
		fake_file = ['\n', 'package:val\n', 'acCepT-OrigiN: val2\n', ' track-oriGin : a  spaced val \n', 'track-version:foo']
		self.c.add(mox.Func(lambda stanza: stanza.get('package') == 'val'))
		self.mox.ReplayAll()

		ret = self.cp.load(fake_file, self.c)
		self.assertEqual(len(ret), 1)
		self.assertEqual(ret[0].get('package'), 'val')

if __name__ == '__main__':
	unittest.main()