def test_var_choices(self): class Context: def resolve(self, _): # pylint: disable=no-self-use return 'z' self.assertEqual( phase3.resolve_value( types.Value(types.Var('foo', choices=('x', 'z'))), Context()), 'z') with self.assertRaises(phase2.InvalidChoice): phase3.resolve_value( types.Value(types.Var('foo', choices=('x', 'y'))), Context())
def test_path(self): class Context: def repath(self, path): # pylint: disable=no-self-use return os.path.join('/root', path) self.assertEqual( phase3.resolve_value(types.Value('foo', is_path=True), Context()), '/root/foo')
def test_call(self): this = self class Context: def call(self, call): # pylint: disable=no-self-use this.assertEqual(call.name, 'foo') return 'myResult' self.assertEqual( phase3.resolve_value(types.Value(types.Call('foo', ())), Context()), 'myResult')
def test_var(self): this = self class Context: def resolve(self, var): # pylint: disable=no-self-use this.assertEqual(var.name, 'foo') return 'myResult' self.assertEqual( phase3.resolve_value(types.Value(types.Var('foo')), Context()), 'myResult')
def test_invalid_value(self): with self.assertRaises(TypeError): phase3.resolve_value(types.Value(object()), None)
def test_string(self): self.assertEqual(phase3.resolve_value(types.Value('foo'), None), 'foo')
def test_bool(self): self.assertEqual(phase3.resolve_value(types.Value(True), None), True) self.assertEqual(phase3.resolve_value(types.Value(False), None), False)
def test_none(self): self.assertIs(phase3.resolve_value(types.Value(None), None), None)