def test_initial_load_win(self): with luci_context.write(something={'data': True}): self.assertDictEqual(luci_context.read_full(), {'something': {'data': True}}) self.assertDictEqual(luci_context._CUR_CONTEXT, {'something': {'data': True}}) self.assertDictEqual(luci_context.read('something'), {'data': True})
def test_initial_load_not_subsection_dict(self): with luci_context._tf({'something': 'string'}) as name: os.environ[self.ek] = name try: self.assertDictEqual(luci_context.read_full(), {}) self.assertDictEqual(luci_context._CUR_CONTEXT, {}) finally: del os.environ[self.ek]
def test_initial_load_not_dict(self): with luci_context._tf('hi') as name: os.environ[self.ek] = name try: self.assertDictEqual(luci_context.read_full(), {}) self.assertDictEqual(luci_context._CUR_CONTEXT, {}) finally: del os.environ[self.ek]
def test_initial_load_not_json(self): with luci_context._tf("not json", data_raw=True) as name: os.environ[self.ek] = name try: self.assertDictEqual(luci_context.read_full(), {}) self.assertDictEqual(luci_context._CUR_CONTEXT, {}) finally: del os.environ[self.ek]
def test_write_unchanged(self): with luci_context.write(something={'data': True}): path = os.environ.get(self.ek) with luci_context.write(): self.assertDictEqual(luci_context.read_full(), {'something': { 'data': True }}) self.assertEqual(os.environ.get(self.ek), path) with luci_context.write(something={'data': True}): self.assertEqual(os.environ.get(self.ek), path) self.assertDictEqual(luci_context.read_full(), {'something': { 'data': True }}) with luci_context.write(something={'data': False}): self.assertNotEqual(os.environ.get(self.ek), path)
def test_initial_load_cannot_read(self): with luci_context._tf({'something': {'data': True}}) as name: os.chmod(name, 0) os.environ[self.ek] = name try: self.assertDictEqual(luci_context.read_full(), {}) self.assertDictEqual(luci_context._CUR_CONTEXT, {}) finally: del os.environ[self.ek]
def test_initial_load_dne(self): self.assertDictEqual(luci_context.read_full(), {}) self.assertDictEqual(luci_context._CUR_CONTEXT, {}) def nope(): raise Exception('I SHOULD NOT BE CALLED') og_load = luci_context._initial_load luci_context._initial_load = nope try: self.assertIsNone(luci_context.read('section')) finally: luci_context._initial_load = og_load