def __init__(self, sources, address=None, exports=None, **kwargs): payload = Payload() payload.add_field('sources', self.create_sources_field(sources, sources_rel_path=address.spec_path, key_arg='sources')) payload.add_field('exports', PrimitivesSetField(exports or [])) super(SourcesTarget, self).__init__(address=address, payload=payload, **kwargs)
def __init__(me, sources, address=None, **kwargs): payload = Payload() payload.add_field( 'sources', me.create_sources_field(sources, sources_rel_path=address.spec_path, key_arg='sources')) super(SourcesTarget, me).__init__(address=address, payload=payload, **kwargs)
def __init__(self, sources, address=None, exports=None, **kwargs): payload = Payload() payload.add_field( "sources", self.create_sources_field( sources, sources_rel_path=address.spec_path, key_arg="sources" ), ) payload.add_field("exports", PrimitivesSetField(exports or [])) super().__init__(address=address, payload=payload, **kwargs)
def test_fingerprint(self): payload = Payload() payload.add_field('foo', PrimitiveField()) fingerprint1 = payload.fingerprint() self.assertEqual(fingerprint1, payload.fingerprint()) payload.add_field('bar', PrimitiveField()) fingerprint2 = payload.fingerprint() self.assertNotEqual(fingerprint1, fingerprint2) self.assertEqual(fingerprint2, payload.fingerprint()) payload.freeze() self.assertEqual(fingerprint2, payload.fingerprint())
def test_partial_fingerprint(self): payload = Payload() payload.add_field('foo', PrimitiveField()) fingerprint1 = payload.fingerprint() self.assertEqual(fingerprint1, payload.fingerprint(field_keys=('foo',))) payload.add_field('bar', PrimitiveField()) fingerprint2 = payload.fingerprint() self.assertEqual(fingerprint1, payload.fingerprint(field_keys=('foo',))) self.assertNotEqual(fingerprint2, payload.fingerprint(field_keys=('foo',))) self.assertNotEqual(fingerprint2, payload.fingerprint(field_keys=('bar',))) self.assertEqual(fingerprint2, payload.fingerprint(field_keys=('bar', 'foo')))
def test_partial_fingerprint(self): payload = Payload() payload.add_field("foo", PrimitiveField()) fingerprint1 = payload.fingerprint() self.assertEqual(fingerprint1, payload.fingerprint(field_keys=("foo",))) payload.add_field("bar", PrimitiveField()) fingerprint2 = payload.fingerprint() self.assertEqual(fingerprint1, payload.fingerprint(field_keys=("foo",))) self.assertNotEqual(fingerprint2, payload.fingerprint(field_keys=("foo",))) self.assertNotEqual(fingerprint2, payload.fingerprint(field_keys=("bar",))) self.assertEqual(fingerprint2, payload.fingerprint(field_keys=("bar", "foo")))
def payload_for_scope(self, scope): """Returns a payload representing the options for the given scope.""" payload = Payload() for (name, _, kwargs) in self.registration_args_iter_for_scope(scope): if not kwargs.get('fingerprint', False): continue val = self.for_scope(scope)[name] val_type = kwargs.get('type', '') if val_type == Options.file: field = FileField(val) elif val_type == Options.target_list: field = TargetListField(val) else: field = PrimitiveField(val) payload.add_field(name, field) payload.freeze() return payload
def test_missing_payload_field(self): payload = Payload() payload.add_field("foo", PrimitiveField("test-value")) payload.add_field("bar", PrimitiveField(None)) self.assertEquals("test-value", payload.foo) self.assertEquals("test-value", payload.get_field("foo").value) self.assertEquals("test-value", payload.get_field_value("foo")) self.assertEquals(None, payload.bar) self.assertEquals(None, payload.get_field("bar").value) self.assertEquals(None, payload.get_field_value("bar")) self.assertEquals(None, payload.get_field("bar", default="nothing").value) self.assertEquals(None, payload.get_field_value("bar", default="nothing")) with self.assertRaises(KeyError): self.assertEquals(None, payload.field_doesnt_exist) self.assertEquals(None, payload.get_field("field_doesnt_exist")) self.assertEquals(None, payload.get_field_value("field_doesnt_exist")) self.assertEquals("nothing", payload.get_field("field_doesnt_exist", default="nothing")) self.assertEquals("nothing", payload.get_field_value("field_doesnt_exist", default="nothing"))
def test_missing_payload_field(self): payload = Payload() payload.add_field('foo', PrimitiveField('test-value')) payload.add_field('bar', PrimitiveField(None)) self.assertEquals('test-value', payload.foo); self.assertEquals('test-value', payload.get_field('foo').value) self.assertEquals('test-value', payload.get_field_value('foo')) self.assertEquals(None, payload.bar); self.assertEquals(None, payload.get_field('bar').value) self.assertEquals(None, payload.get_field_value('bar')) self.assertEquals(None, payload.get_field('bar', default='nothing').value) self.assertEquals(None, payload.get_field_value('bar', default='nothing')) with self.assertRaises(KeyError): self.assertEquals(None, payload.field_doesnt_exist) self.assertEquals(None, payload.get_field('field_doesnt_exist')) self.assertEquals(None, payload.get_field_value('field_doesnt_exist')) self.assertEquals('nothing', payload.get_field('field_doesnt_exist', default='nothing')) self.assertEquals('nothing', payload.get_field_value('field_doesnt_exist', default='nothing'))
def test_missing_payload_field(self): payload = Payload() payload.add_field("foo", PrimitiveField("test-value")) payload.add_field("bar", PrimitiveField(None)) self.assertEqual("test-value", payload.foo) self.assertEqual("test-value", payload.get_field("foo").value) self.assertEqual("test-value", payload.get_field_value("foo")) self.assertEqual(None, payload.bar) self.assertEqual(None, payload.get_field("bar").value) self.assertEqual(None, payload.get_field_value("bar")) self.assertEqual(None, payload.get_field("bar", default="nothing").value) self.assertEqual(None, payload.get_field_value("bar", default="nothing")) with self.assertRaises(AttributeError): self.assertEqual(None, payload.field_doesnt_exist) self.assertEqual(None, payload.get_field("field_doesnt_exist")) self.assertEqual(None, payload.get_field_value("field_doesnt_exist")) self.assertEqual("nothing", payload.get_field("field_doesnt_exist", default="nothing")) self.assertEqual( "nothing", payload.get_field_value("field_doesnt_exist", default="nothing") )
def _make_payload_from_sources(self, sources): p = Payload() p.add_field('sources', SourcesField('', sources)) p.freeze() return p
def test_none(self): payload = Payload() payload.add_field('foo', None) payload2 = Payload() payload2.add_field('foo', PrimitiveField(None)) self.assertNotEqual(payload.fingerprint(), payload2.fingerprint())
def __init__(self, contents, **kwargs): payload = Payload() payload.add_field("contents", PrimitiveField(contents)) super().__init__(payload=payload, **kwargs)
def __init__(self, contents, **kwargs): payload = Payload() payload.add_field('contents', PrimitiveField(contents)) super(MinimalImplResourcesTaskTest.TestTarget, self).__init__(payload=payload, **kwargs)
def test_field_duplication(self): payload = Payload() payload.add_field('foo', PrimitiveField()) payload.freeze() with self.assertRaises(PayloadFieldAlreadyDefinedError): payload.add_field('foo', PrimitiveField())
def test_freeze(self): payload = Payload() payload.add_field('foo', PrimitiveField()) payload.freeze() with self.assertRaises(PayloadFrozenError): payload.add_field('bar', PrimitiveField())
def __init__(me, sources, address=None, **kwargs): payload = Payload() payload.add_field('sources', me.create_sources_field(sources, sources_rel_path=address.spec_path, key_arg='sources')) super(SourcesTarget, me).__init__(address=address, payload=payload, **kwargs)