def check_virtual_options(self, name, vsphere): self.assertEqual(set(['test', 'develop']), vsphere.leaves) self.assertEqual(set(['dummy/virtual/test/%s' % name, 'dummy/virtual/develop/%s' % name]), set(vsphere.resource_leaves)) settings = Settings() settings.user['test'] = False self.assertEqual('dummy/virtual/develop/%s' % name, vsphere.evaluate(settings)) settings.user['test'] = True self.assertEqual('dummy/virtual/test/%s' % name, vsphere.evaluate(settings))
def virtual_test(self): references = References() references[va].add('a.h') code = ( 'def virtual(settings):\n\tif(settings.os.family == "windows"):return "win"\n' '\telse: return "nix"') a = Resource(VirtualCell('user/blocka/a.h', code, {'win', 'nix'})) awin = Resource(SimpleCell('user/blocka/win/a.h')) anix = Resource(SimpleCell('user/blocka/nix/a.h')) b = Resource(SimpleCell('user/blockb/b.h')) d1 = Resource(SimpleCell('user/blockd/d.h')) awin.cell.dependencies.explicit.add(b.name) anix.cell.dependencies.explicit.add(d1.name) tables = {va: [vb, vd1], vb: [], vd1: []} api = FakeApi(zip([va, va, va, vb, vd1], [a, awin, anix, b, d1]), tables) #With windows settings settings = Settings(OSInfo(OSFamily("Windows"))) biiout = OutputStream() graph, closure, _ = build_closure(api, references, {}, settings, biiout) expected_graph = BlockVersionGraph() expected_graph.add_nodes([va, vb]) expected_graph.add_edge(va, vb) self.assertEqual(expected_graph, graph) expected_closure = Closure({ a.name: ClosureItem(a, va), awin.name: ClosureItem(awin, va), b.name: ClosureItem(b, vb), }) self.assertEqual(expected_closure, closure) self.assertEqual("", str(biiout)) #Change settings settings = Settings(OSInfo(OSFamily("Linux"))) biiout = OutputStream() graph, closure, _ = build_closure(api, references, {}, settings, biiout) expected_graph = BlockVersionGraph() expected_graph.add_nodes([va, vd1]) expected_graph.add_edge(va, vd1) self.assertEqual(expected_graph, graph) expected_closure = Closure({ a.name: ClosureItem(a, va), anix.name: ClosureItem(anix, va), d1.name: ClosureItem(d1, vd1), }) self.assertEqual(expected_closure, closure) self.assertEqual("", str(biiout))
def check_virtual_options(self, name, vsphere): self.assertEqual(set(['test', 'develop']), vsphere.leaves) self.assertEqual( set([ 'dummy/virtual/test/%s' % name, 'dummy/virtual/develop/%s' % name ]), set(vsphere.resource_leaves)) settings = Settings() settings.user['test'] = False self.assertEqual('dummy/virtual/develop/%s' % name, vsphere.evaluate(settings)) settings.user['test'] = True self.assertEqual('dummy/virtual/test/%s' % name, vsphere.evaluate(settings))
def settings(self): """ Return Hive settings. If settings.bii not present, creates and initialize a default hive settings.bii """ if self._settings is None: settings_path = self._bii_paths.settings if not os.path.exists(settings_path): # CREATE new hive settings file settings = Settings() # empty settings, only OS information save(settings_path, settings.dumps()) # save settings.bii self._settings = settings else: # LOAD existing settings.bii file try: self._settings = Settings.loads(load(settings_path)) except Exception as e: raise ClientException('%s\nIn file %s' % (str(e), settings_path.replace('\\', '/'))) return self._settings
def _sphere_os_checks(self, name): vsphere = self.block_holder[name].cell self.assertTrue(isinstance(vsphere, VirtualCell), '%s is not a VirtualCell' % vsphere.name) self.assertEqual(set(['win', 'nix']), vsphere.leaves) self.assertEqual(set(['user/block/win/%s' % name, 'user/block/nix/%s' % name]), set(vsphere.resource_leaves)) settings = Settings(OSInfo('linux')) self.assertEqual('user/block/nix/%s' % name, vsphere.evaluate(settings)) settings = Settings(OSInfo('windows')) self.assertEqual('user/block/win/%s' % name, vsphere.evaluate(settings)) winsphere = self.block_holder['win/%s' % name].cell self.assertTrue(isinstance(winsphere, SimpleCell)) nixsphere = self.block_holder['nix/%s' % name].cell self.assertTrue(isinstance(nixsphere, SimpleCell))
def settings(self): """ Return Hive settings. If settings.bii not present, creates and initialize a default hive settings.bii """ if self._settings is None: settings_path = self._bii_paths.settings if not os.path.exists( settings_path): # CREATE new hive settings file settings = Settings() # empty settings, only OS information save(settings_path, settings.dumps()) # save settings.bii self._settings = settings else: # LOAD existing settings.bii file try: self._settings = Settings.loads(load(settings_path)) except Exception as e: raise ClientException( '%s\nIn file %s' % (str(e), settings_path.replace('\\', '/'))) return self._settings
def deserialize(data): try: hive = Hive() hive.hive_dependencies = HiveDependencies.deserialize( data[Hive.SERIAL_HIVE_DEPENDENCIES]) hive._cells = SetDeserializer(BlockCellName).deserialize(data[Hive.SERIAL_CELLS_KEY]) hive.settings = Settings.deserialize(data[Hive.SERIAL_SETTINGS]) return hive except Exception as e: raise BiiSerializationException(e)
def test_no_ide(self): settings = Settings() user_io = mocked_user_io() mock_user_io(user_io, { 'username': '******', 'IP Address': '127.1.2.3', 'directory': 'mydir' }) rpi_settings_wizard(user_io, settings) self.assertEqual(settings.rpi.directory, 'mydir') self.assertEqual(settings.rpi.ip, '127.1.2.3') self.assertEqual(settings.rpi.user, 'piuser')
def test_user_defined_settings(self): raw_settings = '''cmake: {generator: Visual} os: {arch: 64bit, family: MacOS, version: 10.9.1} user: {my_definition: hola, my_other_definition: adios} ''' settings = Settings.loads(raw_settings) self.assertTrue(hasattr(settings, 'user')) self.assertIn('my_definition', settings.user) self.assertEquals('hola', settings.user['my_definition']) self.assertEquals('adios', settings.user['my_other_definition']) dump = settings.dumps() self.assertEquals(raw_settings, dump)
def testBasic(self): s = Settings() s.os.family = OSFamily('Linux') self.assertEqual('user/module/path/to/nix/file.h', self.r.evaluate(s)) s.os.family = OSFamily('Windows') self.assertEqual('user/module/path/to/win/file.h', self.r.evaluate(s))
import unittest from biicode.common.settings.settings import Settings import copy from biicode.common.settings.tools import Builder class SettingsTest(unittest.TestCase): def test_copy(self): s = Settings() s.cpp.builder = Builder(family='make') s2 = copy.deepcopy(s.cpp) self.assertEqual(s.cpp, s2) if __name__ == "__main__": a = Settings.loads("{cpp: {kk: aux}}") print a.kk