コード例 #1
0
 def testSettingsOverridesLoading(self):
     with tempfile.NamedTemporaryFile(mode='w', delete=False) as tf:
         tf.write(VALID_CONF)
         os.environ['PLAIDML_SETTINGS'] = tf.name
     os.environ['PLAIDML_CONFIG'] = 'other'
     settings._load()
     self.assertEquals(settings.config, 'other')
     os.remove(tf.name)
コード例 #2
0
    def testSettingsFileLoading(self):
        with tempfile.NamedTemporaryFile(mode='w', delete=False) as val:
            val.write(VALID_CONF)
        with tempfile.NamedTemporaryFile(mode='w', delete=False) as inv:
            inv.write(INVALID_CONF)
        # Explicit settings files should take precedence
        settings._setup_for_test(inv.name, inv.name)
        os.environ['PLAIDML_SETTINGS'] = val.name
        settings._load()
        self.assertEquals(settings.config, 'tmp')
        self.assertEquals(settings.experimental, True)
        self.assertEquals(settings.device_ids, ['1', '3', '5'])

        # User config should shadow system config
        settings._setup_for_test(val.name, inv.name)
        settings._load()
        self.assertEquals(settings.experimental, True)
        settings._setup_for_test('nottafile', inv.name)
        with self.assertRaises(plaidml.exceptions.OutOfRange):
            settings._load()
        os.remove(val.name)
        os.remove(inv.name)