vasm / src / tests / test_bootmode.py

#!/usr/bin/env python

#    This file is part of VASM.
#
#    VASM is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v3 as published by
#    the Free Software Foundation.
#
#    VASM 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 VASM.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "Moises Henriquez"
__author_email__ = "moc.liamg@xnl.E0M"[::-1]


import os
import sys
import shutil
import unittest
vasmdir = os.path.join(os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))), 'vasm')
if not vasmdir in sys.path: sys.path.append(vasmdir)
from backend import bootmode



class BootModeTest(unittest.TestCase):
    def setUp(self):
        self.file = "/tmp/inittab"
        shutil.copy2("/etc/inittab", "/tmp/inittab")
        self.model = bootmode.InitTab(self.file)
        self._original_data = []
        with open(self.file) as file:
            for line in file:
                self._original_data.append(line)
        
    
    def tearDown(self):
        # remove the temp file
        os.remove("/tmp/inittab")
    
    def test_methods(self):
        """ Test to make sure the class has the right methods """
        self.assertTrue(callable(self.model.getMode))
        self.assertTrue(callable(self.model.setMode))

    def test_getMode(self):
        mode = self.model.getMode()
        self.assertTrue(type(mode) == int)
    
    def test_setMode(self):
        # copy the file to tmp
        mode = 3
        self.model.setMode(mode)
        # make sure when we read it, it comes back the same as it went in
        result = self.model.getMode()
        self.assertEqual(mode, result)
        
        # Check that this method raises an exception if fed the wrong values
        self.assertRaises(AssertionError, self.model.setMode, 0)
        self.assertRaises(AssertionError, self.model.setMode, 6)

if __name__ == "__main__":
    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.