def test_menuconfig_is_run_when_reconfigure_is_set(self): """If a reconfigure argument is passed, menuconfig is always run""" os.mkdir(self.statedir) pathlib.Path(self.configfile).touch() mconfig = Mock(menuconfig) jhalfs.JHalfs(mconfig=mconfig, reconf=True) mconfig.menuconfig.assert_called()
def test_exit_when_no_config_saved(self): """If no config, menuconfig is run and no config is saved, exit""" mconfig = Mock(menuconfig) # noinspection PyTypeChecker with self.assertRaises((jhalfs.JHalfsException, SystemExit)): jhalfs.JHalfs(mconfig=mconfig) mconfig.menuconfig.assert_called()
def test_menuconfig_is_not_run_when_config_exists(self): """If a previous .jhalfs/config file does exist don't run menuconfig""" os.mkdir(self.statedir) pathlib.Path(self.configfile).touch() pathlib.Path('{}/LFS'.format(self.statedir)).touch() mconfig = Mock(menuconfig) jhalfs.JHalfs(mconfig=mconfig) mconfig.menuconfig.assert_not_called()
def test_statedir_when_HOME_is_unset(self): """New instances of JHalfs will use a statedir in CWD if HOME unset""" os.environ.pop('HOME', None) statedir = '{}/.jhalfs'.format(self.althomedir) self.configfile = '{}/config'.format(statedir) alfs = jhalfs.JHalfs(mconfig=self.mconfig) self.assertEqual(statedir, alfs.statedir) self.assertEqual(self.configfile, alfs.configfile)
def test_statedir_when_HOME_is_set(self): """New instances of JHalfs will have a property called statedir. Its value will be $HOME/.jhalfs if $HOME is set. The config file will be [statedir]/config.""" self.assertEqual(os.environ['HOME'], self.homedir) self.assertTrue(os.path.isdir(self.homedir)) alfs = jhalfs.JHalfs(mconfig=self.mconfig) self.assertEqual(self.statedir, alfs.statedir) self.assertTrue(self.homedir in alfs.statedir) self.assertEqual(self.configfile, alfs.configfile) self.assertTrue(self.statedir in alfs.configfile)
def test_menuconfig_is_run_when_no_config(self): """If a previous .jhalfs/config file doesn't exist run menuconfig""" jhalfs.JHalfs(mconfig=self.mconfig) self.mconfig.menuconfig.assert_called()
def test_config_is_set_correctly(self): """Test that the kconf file is set in the environment""" alfs = jhalfs.JHalfs(mconfig=self.mconfig) self.assertEqual(self.configfile, os.getenv('KCONFIG_CONFIG')) self.assertEqual(alfs.configfile, os.getenv('KCONFIG_CONFIG'))
def test_statedir_failed_create(self): """Test that a JHalfsException is raised on failed dir creation""" os.environ['HOME'] = '/dev/null' # noinspection PyTypeChecker with self.assertRaises((jhalfs.JHalfsException, SystemExit)): jhalfs.JHalfs(mconfig=self.mconfig)
def test_statedir_exists(self): """New instances of JHalfs will create a statedir if not present""" alfs = jhalfs.JHalfs(mconfig=self.mconfig) self.assertTrue(os.path.isdir(alfs.statedir))
def test_config_values_are_loaded(self): """Ensure the values from the config file are properly loaded""" alfs = jhalfs.JHalfs(mconfig=self.mconfig) self.assertEqual(alfs.config, EXPECTED_CONFIG)