'Test that PathSpec works.'

def testPathSpec(self):

    pathspec_pb = jobs_pb2.PathSpec(path='/', pathtype=1)
    pathspec_pb.nested_path.path = 'foo'
    pathspec_pb.nested_path.pathtype = 2
    reference_pathspec = rdf_paths.PathSpec.FromSerializedString(pathspec_pb.SerializeToString())
    pathspec = rdf_paths.PathSpec()
    pathspec.path = '/'
    pathspec.pathtype = 1
    pathspec.Append(path='foo', pathtype=2)
    self.assertRDFValuesEqual(pathspec, reference_pathspec)
    pathspec = rdf_paths.PathSpec(path='/', pathtype=1)
    pathspec.Append(path='foo', pathtype=2)
    self.assertRDFValuesEqual(pathspec, reference_pathspec)
    pathspec = pathspec.Copy()
    self.assertRDFValuesEqual(pathspec, reference_pathspec)
    self.assertEqual(pathspec.path, '/')
    self.assertEqual(pathspec.last.path, 'foo')
    pathspec.first.path = 'test'
    self.assertEqual(pathspec.last.path, 'foo')
    self.assertEqual([x.path for x in pathspec], ['test', 'foo'])
    self.assertEqual(len(pathspec), 2)
    pathspec = rdf_paths.PathSpec(path='/foo', pathtype=1)
    pathspec.Append(path='/', pathtype=0)
    self.assertEqual(pathspec.Dirname().CollapsePath(), '/')
    pathspec.Append(path='sdasda', pathtype=0)
    self.assertEqual(pathspec.Dirname().CollapsePath(), '/foo')
    pathspec = rdf_paths.PathSpec(path='/foo', pathtype=1)
    pathspec_base = rdf_paths.PathSpec()
    pathspec_base.Append(pathspec)
    self.assertEqual(pathspec_base.CollapsePath(), '/foo')
    pathspec_base = rdf_paths.PathSpec()
    pathspec_base.Insert(0, path='/foo', pathtype=1)
    self.assertEqual(pathspec_base.CollapsePath(), '/foo')
