示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
文件: test_target.py 项目: wiwa/pants
 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)
示例#5
0
 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())
示例#6
0
 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')))
示例#7
0
 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")))
示例#8
0
 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")))
示例#9
0
 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
示例#10
0
 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"))
示例#11
0
 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'))
示例#12
0
 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
示例#14
0
 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())
示例#15
0
 def __init__(self, contents, **kwargs):
     payload = Payload()
     payload.add_field("contents", PrimitiveField(contents))
     super().__init__(payload=payload, **kwargs)
示例#16
0
 def __init__(self, contents, **kwargs):
   payload = Payload()
   payload.add_field('contents', PrimitiveField(contents))
   super(MinimalImplResourcesTaskTest.TestTarget, self).__init__(payload=payload, **kwargs)
示例#17
0
 def test_field_duplication(self):
   payload = Payload()
   payload.add_field('foo', PrimitiveField())
   payload.freeze()
   with self.assertRaises(PayloadFieldAlreadyDefinedError):
     payload.add_field('foo', PrimitiveField())
示例#18
0
 def test_freeze(self):
   payload = Payload()
   payload.add_field('foo', PrimitiveField())
   payload.freeze()
   with self.assertRaises(PayloadFrozenError):
     payload.add_field('bar', PrimitiveField())
示例#19
0
 def _make_payload_from_sources(self, sources):
     p = Payload()
     p.add_field('sources', SourcesField('', sources))
     p.freeze()
     return p
示例#20
0
 def __init__(self, contents, **kwargs):
   payload = Payload()
   payload.add_field('contents', PrimitiveField(contents))
   super(MinimalImplResourcesTaskTest.TestTarget, self).__init__(payload=payload, **kwargs)
示例#21
0
 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)