Skip to content

Commit

Permalink
[#20] Start working on testing FreeBSDUtils with pytest
Browse files Browse the repository at this point in the history
Test case for FreeBSDUtils.reboot
  • Loading branch information
iblislin committed Sep 4, 2015
1 parent 0a15509 commit 3c58b6c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cloudbaseinit/osutils/freebsd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from cloudbaseinit.osutils import base

from subprocess import CalledProcessError
import subprocess
import datetime
import subprocess
import os
import os.path

from subprocess import CalledProcessError
from cloudbaseinit.osutils import base


class FreeBSDUtils(base.BaseOSUtils):
def reboot(self):
if ( os.system('reboot') != 0 ):
raise Exception('Reboot failed')
if os.system('reboot') != 0:
raise OSError('Reboot failed')

def user_exists(self, username):
try:
Expand Down
22 changes: 22 additions & 0 deletions cloudbaseinit/tests/osutils/test_freebsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest

try:
import unittest.mock as mock
except ImportError:
import mock

from cloudbaseinit.osutils.freebsd import FreeBSDUtils
from pytest import raises


class TestFreeBSDUtils():
def setup_method(self, method):
self.bsd = FreeBSDUtils()

def teardown_method(self, method):
del self.bsd

@mock.patch('cloudbaseinit.osutils.freebsd.os.system', return_value=1)
def test_reboot(self, system):
with raises(OSError):
self.bsd.reboot()
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sphinx>=1.1.2,<1.1.999
oslosphinx
testtools>=0.9.32
testrepository>=0.0.18
pytest

0 comments on commit 3c58b6c

Please sign in to comment.