diff --git "a/codeparrot-valid_1029.txt" "b/codeparrot-valid_1029.txt" new file mode 100644--- /dev/null +++ "b/codeparrot-valid_1029.txt" @@ -0,0 +1,10000 @@ + return [] + + def _check_list_max_show_all(self, cls, model): + """ Check that list_max_show_all is an integer. """ + + if not isinstance(cls.list_max_show_all, int): + return must_be('an integer', option='list_max_show_all', obj=cls, id='admin.E119') + else: + return [] + + def _check_list_editable(self, cls, model): + """ Check that list_editable is a sequence of editable fields from + list_display without first element. """ + + if not isinstance(cls.list_editable, (list, tuple)): + return must_be('a list or tuple', option='list_editable', obj=cls, id='admin.E120') + else: + return list(chain(*[ + self._check_list_editable_item(cls, model, item, "list_editable[%d]" % index) + for index, item in enumerate(cls.list_editable) + ])) + + def _check_list_editable_item(self, cls, model, field_name, label): + try: + field = model._meta.get_field(field_name) + except FieldDoesNotExist: + return refer_to_missing_field(field=field_name, option=label, + model=model, obj=cls, id='admin.E121') + else: + if field_name not in cls.list_display: + return refer_to_missing_field(field=field_name, option=label, + model=model, obj=cls, id='admin.E122') + + checks.Error( + "The value of '%s' refers to '%s', which is not contained in 'list_display'." % ( + label, field_name + ), + hint=None, + obj=cls, + id='admin.E122', + ), + elif cls.list_display_links and field_name in cls.list_display_links: + return [ + checks.Error( + "The value of '%s' cannot be in both 'list_editable' and 'list_display_links'." % field_name, + hint=None, + obj=cls, + id='admin.E123', + ) + ] + # Check that list_display_links is set, and that the first values of list_editable and list_display are + # not the same. See ticket #22792 for the use case relating to this. + elif (cls.list_display[0] in cls.list_editable and cls.list_display[0] != cls.list_editable[0] and + cls.list_display_links is not None): + return [ + checks.Error( + "The value of '%s' refers to the first field in 'list_display' ('%s'), " + "which cannot be used unless 'list_display_links' is set." % ( + label, cls.list_display[0] + ), + hint=None, + obj=cls, + id='admin.E124', + ) + ] + elif not field.editable: + return [ + checks.Error( + "The value of '%s' refers to '%s', which is not editable through the admin." % ( + label, field_name + ), + hint=None, + obj=cls, + id='admin.E125', + ) + ] + else: + return [] + + def _check_search_fields(self, cls, model): + """ Check search_fields is a sequence. """ + + if not isinstance(cls.search_fields, (list, tuple)): + return must_be('a list or tuple', option='search_fields', obj=cls, id='admin.E126') + else: + return [] + + def _check_date_hierarchy(self, cls, model): + """ Check that date_hierarchy refers to DateField or DateTimeField. """ + + if cls.date_hierarchy is None: + return [] + else: + try: + field = model._meta.get_field(cls.date_hierarchy) + except FieldDoesNotExist: + return refer_to_missing_field(option='date_hierarchy', + field=cls.date_hierarchy, + model=model, obj=cls, id='admin.E127') + else: + if not isinstance(field, (models.DateField, models.DateTimeField)): + return must_be('a DateField or DateTimeField', option='date_hierarchy', + obj=cls, id='admin.E128') + else: + return [] + + +class InlineModelAdminChecks(BaseModelAdminChecks): + + def check(self, cls, parent_model, **kwargs): + errors = super(InlineModelAdminChecks, self).check(cls, model=cls.model, **kwargs) + errors.extend(self._check_relation(cls, parent_model)) + errors.extend(self._check_exclude_of_parent_model(cls, parent_model)) + errors.extend(self._check_extra(cls)) + errors.extend(self._check_max_num(cls)) + errors.extend(self._check_min_num(cls)) + errors.extend(self._check_formset(cls)) + return errors + + def _check_exclude_of_parent_model(self, cls, parent_model): + # Do not perform more specific checks if the base checks result in an + # error. + errors = super(InlineModelAdminChecks, self)._check_exclude(cls, parent_model) + if errors: + return [] + + # Skip if `fk_name` is invalid. + if self._check_relation(cls, parent_model): + return [] + + if cls.exclude is None: + return [] + + fk = _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name) + if fk.name in cls.exclude: + return [ + checks.Error( + "Cannot exclude the field '%s', because it is the foreign key " + "to the parent model '%s.%s'." % ( + fk.name, parent_model._meta.app_label, parent_model._meta.object_name + ), + hint=None, + obj=cls, + id='admin.E201', + ) + ] + else: + return [] + + def _check_relation(self, cls, parent_model): + try: + _get_foreign_key(parent_model, cls.model, fk_name=cls.fk_name) + except ValueError as e: + return [checks.Error(e.args[0], hint=None, obj=cls, id='admin.E202')] + else: + return [] + + def _check_extra(self, cls): + """ Check that extra is an integer. """ + + if not isinstance(cls.extra, int): + return must_be('an integer', option='extra', obj=cls, id='admin.E203') + else: + return [] + + def _check_max_num(self, cls): + """ Check that max_num is an integer. """ + + if cls.max_num is None: + return [] + elif not isinstance(cls.max_num, int): + return must_be('an integer', option='max_num', obj=cls, id='admin.E204') + else: + return [] + + def _check_min_num(self, cls): + """ Check that min_num is an integer. """ + + if cls.min_num is None: + return [] + elif not isinstance(cls.min_num, int): + return must_be('an integer', option='min_num', obj=cls, id='admin.E205') + else: + return [] + + def _check_formset(self, cls): + """ Check formset is a subclass of BaseModelFormSet. """ + + if not issubclass(cls.formset, BaseModelFormSet): + return must_inherit_from(parent='BaseModelFormSet', option='formset', + obj=cls, id='admin.E206') + else: + return [] + + +def must_be(type, option, obj, id): + return [ + checks.Error( + "The value of '%s' must be %s." % (option, type), + hint=None, + obj=obj, + id=id, + ), + ] + + +def must_inherit_from(parent, option, obj, id): + return [ + checks.Error( + "The value of '%s' must inherit from '%s'." % (option, parent), + hint=None, + obj=obj, + id=id, + ), + ] + + +def refer_to_missing_field(field, option, model, obj, id): + return [ + checks.Error( + "The value of '%s' refers to '%s', which is not an attribute of '%s.%s'." % ( + option, field, model._meta.app_label, model._meta.object_name + ), + hint=None, + obj=obj, + id=id, + ), + ] + +#!/usr/bin/env python + +# Software License Agreement (BSD License) +# +# Copyright (c) 2013, Willow Garage, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# Author: Ioan Sucan + +import sys +import rospy +from moveit_commander import RobotCommander, PlanningSceneInterface, roscpp_initialize, roscpp_shutdown +from geometry_msgs.msg import PoseStamped + +if __name__=='__main__': + + roscpp_initialize(sys.argv) + rospy.init_node('moveit_py_demo', anonymous=True) + + scene = PlanningSceneInterface() + robot = RobotCommander() + rospy.sleep(1) + + # clean the scene + scene.remove_world_object("pole") + scene.remove_world_object("table") + scene.remove_world_object("part") + + # publish a demo scene + p = PoseStamped() + p.header.frame_id = robot.get_planning_frame() + p.pose.position.x = 0.7 + p.pose.position.y = -0.4 + p.pose.position.z = 0.85 + p.pose.orientation.w = 1.0 + scene.add_box("pole", p, (0.3, 0.1, 1.0)) + + p.pose.position.y = -0.2 + p.pose.position.z = 0.175 + scene.add_box("table", p, (0.5, 1.5, 0.35)) + + p.pose.position.x = 0.6 + p.pose.position.y = -0.7 + p.pose.position.z = 0.5 + scene.add_box("part", p, (0.15, 0.1, 0.3)) + + rospy.sleep(1) + + # pick an object + robot.right_arm.pick("part") + + rospy.spin() + roscpp_shutdown() + +# -*- coding: utf-8 -*- +"""Tests for Beautiful Soup's tree traversal methods. + +The tree traversal methods are the main advantage of using Beautiful +Soup over just using a parser. + +Different parsers will build different Beautiful Soup trees given the +same markup, but all Beautiful Soup trees can be traversed with the +methods tested here. +""" + +import copy +import pickle +import re +import warnings +from bs4 import BeautifulSoup +from bs4.builder import ( + builder_registry, + HTMLParserTreeBuilder, +) +from bs4.element import ( + CData, + Comment, + Doctype, + NavigableString, + SoupStrainer, + Tag, +) +from bs4.testing import ( + SoupTest, + skipIf, +) + +XML_BUILDER_PRESENT = (builder_registry.lookup("xml") is not None) +LXML_PRESENT = (builder_registry.lookup("lxml") is not None) + +class TreeTest(SoupTest): + + def assertSelects(self, tags, should_match): + """Make sure that the given tags have the correct text. + + This is used in tests that define a bunch of tags, each + containing a single string, and then select certain strings by + some mechanism. + """ + self.assertEqual([tag.string for tag in tags], should_match) + + def assertSelectsIDs(self, tags, should_match): + """Make sure that the given tags have the correct IDs. + + This is used in tests that define a bunch of tags, each + containing a single string, and then select certain strings by + some mechanism. + """ + self.assertEqual([tag['id'] for tag in tags], should_match) + + +class TestFind(TreeTest): + """Basic tests of the find() method. + + find() just calls find_all() with limit=1, so it's not tested all + that thouroughly here. + """ + + def test_find_tag(self): + soup = self.soup("1234") + self.assertEqual(soup.find("b").string, "2") + + def test_unicode_text_find(self): + soup = self.soup(u'

Räksmörgås

') + self.assertEqual(soup.find(text=u'Räksmörgås'), u'Räksmörgås') + + def test_find_everything(self): + """Test an optimization that finds all tags.""" + soup = self.soup("foobar") + self.assertEqual(2, len(soup.find_all())) + + def test_find_everything_with_name(self): + """Test an optimization that finds all tags with a given name.""" + soup = self.soup("foobarbaz") + self.assertEqual(2, len(soup.find_all('a'))) + +class TestFindAll(TreeTest): + """Basic tests of the find_all() method.""" + + def test_find_all_text_nodes(self): + """You can search the tree for text nodes.""" + soup = self.soup("Foobar\xbb") + # Exact match. + self.assertEqual(soup.find_all(text="bar"), [u"bar"]) + # Match any of a number of strings. + self.assertEqual( + soup.find_all(text=["Foo", "bar"]), [u"Foo", u"bar"]) + # Match a regular expression. + self.assertEqual(soup.find_all(text=re.compile('.*')), + [u"Foo", u"bar", u'\xbb']) + # Match anything. + self.assertEqual(soup.find_all(text=True), + [u"Foo", u"bar", u'\xbb']) + + def test_find_all_limit(self): + """You can limit the number of items returned by find_all.""" + soup = self.soup("12345") + self.assertSelects(soup.find_all('a', limit=3), ["1", "2", "3"]) + self.assertSelects(soup.find_all('a', limit=1), ["1"]) + self.assertSelects( + soup.find_all('a', limit=10), ["1", "2", "3", "4", "5"]) + + # A limit of 0 means no limit. + self.assertSelects( + soup.find_all('a', limit=0), ["1", "2", "3", "4", "5"]) + + def test_calling_a_tag_is_calling_findall(self): + soup = self.soup("123") + self.assertSelects(soup('a', limit=1), ["1"]) + self.assertSelects(soup.b(id="foo"), ["3"]) + + def test_find_all_with_self_referential_data_structure_does_not_cause_infinite_recursion(self): + soup = self.soup("") + # Create a self-referential list. + l = [] + l.append(l) + + # Without special code in _normalize_search_value, this would cause infinite + # recursion. + self.assertEqual([], soup.find_all(l)) + + def test_find_all_resultset(self): + """All find_all calls return a ResultSet""" + soup = self.soup("") + result = soup.find_all("a") + self.assertTrue(hasattr(result, "source")) + + result = soup.find_all(True) + self.assertTrue(hasattr(result, "source")) + + result = soup.find_all(text="foo") + self.assertTrue(hasattr(result, "source")) + + +class TestFindAllBasicNamespaces(TreeTest): + + def test_find_by_namespaced_name(self): + soup = self.soup('4') + self.assertEqual("4", soup.find("mathml:msqrt").string) + self.assertEqual("a", soup.find(attrs= { "svg:fill" : "red" }).name) + + +class TestFindAllByName(TreeTest): + """Test ways of finding tags by tag name.""" + + def setUp(self): + super(TreeTest, self).setUp() + self.tree = self.soup("""First tag. + Second tag. + Third Nested tag. tag.""") + + def test_find_all_by_tag_name(self): + # Find all the tags. + self.assertSelects( + self.tree.find_all('a'), ['First tag.', 'Nested tag.']) + + def test_find_all_by_name_and_text(self): + self.assertSelects( + self.tree.find_all('a', text='First tag.'), ['First tag.']) + + self.assertSelects( + self.tree.find_all('a', text=True), ['First tag.', 'Nested tag.']) + + self.assertSelects( + self.tree.find_all('a', text=re.compile("tag")), + ['First tag.', 'Nested tag.']) + + + def test_find_all_on_non_root_element(self): + # You can call find_all on any node, not just the root. + self.assertSelects(self.tree.c.find_all('a'), ['Nested tag.']) + + def test_calling_element_invokes_find_all(self): + self.assertSelects(self.tree('a'), ['First tag.', 'Nested tag.']) + + def test_find_all_by_tag_strainer(self): + self.assertSelects( + self.tree.find_all(SoupStrainer('a')), + ['First tag.', 'Nested tag.']) + + def test_find_all_by_tag_names(self): + self.assertSelects( + self.tree.find_all(['a', 'b']), + ['First tag.', 'Second tag.', 'Nested tag.']) + + def test_find_all_by_tag_dict(self): + self.assertSelects( + self.tree.find_all({'a' : True, 'b' : True}), + ['First tag.', 'Second tag.', 'Nested tag.']) + + def test_find_all_by_tag_re(self): + self.assertSelects( + self.tree.find_all(re.compile('^[ab]$')), + ['First tag.', 'Second tag.', 'Nested tag.']) + + def test_find_all_with_tags_matching_method(self): + # You can define an oracle method that determines whether + # a tag matches the search. + def id_matches_name(tag): + return tag.name == tag.get('id') + + tree = self.soup("""Match 1. + Does not match. + Match 2.""") + + self.assertSelects( + tree.find_all(id_matches_name), ["Match 1.", "Match 2."]) + + +class TestFindAllByAttribute(TreeTest): + + def test_find_all_by_attribute_name(self): + # You can pass in keyword arguments to find_all to search by + # attribute. + tree = self.soup(""" + Matching a. + + Non-matching Matching b.a. + """) + self.assertSelects(tree.find_all(id='first'), + ["Matching a.", "Matching b."]) + + def test_find_all_by_utf8_attribute_value(self): + peace = u"םולש".encode("utf8") + data = u''.encode("utf8") + soup = self.soup(data) + self.assertEqual([soup.a], soup.find_all(title=peace)) + self.assertEqual([soup.a], soup.find_all(title=peace.decode("utf8"))) + self.assertEqual([soup.a], soup.find_all(title=[peace, "something else"])) + + def test_find_all_by_attribute_dict(self): + # You can pass in a dictionary as the argument 'attrs'. This + # lets you search for attributes like 'name' (a fixed argument + # to find_all) and 'class' (a reserved word in Python.) + tree = self.soup(""" + Name match. + Class match. + Non-match. + A tag called 'name1'. + """) + + # This doesn't do what you want. + self.assertSelects(tree.find_all(name='name1'), + ["A tag called 'name1'."]) + # This does what you want. + self.assertSelects(tree.find_all(attrs={'name' : 'name1'}), + ["Name match."]) + + self.assertSelects(tree.find_all(attrs={'class' : 'class2'}), + ["Class match."]) + + def test_find_all_by_class(self): + tree = self.soup(""" + Class 1. + Class 2. + Class 1. + Class 3 and 4. + """) + + # Passing in the class_ keyword argument will search against + # the 'class' attribute. + self.assertSelects(tree.find_all('a', class_='1'), ['Class 1.']) + self.assertSelects(tree.find_all('c', class_='3'), ['Class 3 and 4.']) + self.assertSelects(tree.find_all('c', class_='4'), ['Class 3 and 4.']) + + # Passing in a string to 'attrs' will also search the CSS class. + self.assertSelects(tree.find_all('a', '1'), ['Class 1.']) + self.assertSelects(tree.find_all(attrs='1'), ['Class 1.', 'Class 1.']) + self.assertSelects(tree.find_all('c', '3'), ['Class 3 and 4.']) + self.assertSelects(tree.find_all('c', '4'), ['Class 3 and 4.']) + + def test_find_by_class_when_multiple_classes_present(self): + tree = self.soup("Found it") + + f = tree.find_all("gar", class_=re.compile("o")) + self.assertSelects(f, ["Found it"]) + + f = tree.find_all("gar", class_=re.compile("a")) + self.assertSelects(f, ["Found it"]) + + # Since the class is not the string "foo bar", but the two + # strings "foo" and "bar", this will not find anything. + f = tree.find_all("gar", class_=re.compile("o b")) + self.assertSelects(f, []) + + def test_find_all_with_non_dictionary_for_attrs_finds_by_class(self): + soup = self.soup("Found it") + + self.assertSelects(soup.find_all("a", re.compile("ba")), ["Found it"]) + + def big_attribute_value(value): + return len(value) > 3 + + self.assertSelects(soup.find_all("a", big_attribute_value), []) + + def small_attribute_value(value): + return len(value) <= 3 + + self.assertSelects( + soup.find_all("a", small_attribute_value), ["Found it"]) + + def test_find_all_with_string_for_attrs_finds_multiple_classes(self): + soup = self.soup('') + a, a2 = soup.find_all("a") + self.assertEqual([a, a2], soup.find_all("a", "foo")) + self.assertEqual([a], soup.find_all("a", "bar")) + + # If you specify the class as a string that contains a + # space, only that specific value will be found. + self.assertEqual([a], soup.find_all("a", class_="foo bar")) + self.assertEqual([a], soup.find_all("a", "foo bar")) + self.assertEqual([], soup.find_all("a", "bar foo")) + + def test_find_all_by_attribute_soupstrainer(self): + tree = self.soup(""" + Match. + Non-match.""") + + strainer = SoupStrainer(attrs={'id' : 'first'}) + self.assertSelects(tree.find_all(strainer), ['Match.']) + + def test_find_all_with_missing_atribute(self): + # You can pass in None as the value of an attribute to find_all. + # This will match tags that do not have that attribute set. + tree = self.soup("""ID present. + No ID present. + ID is empty.""") + self.assertSelects(tree.find_all('a', id=None), ["No ID present."]) + + def test_find_all_with_defined_attribute(self): + # You can pass in None as the value of an attribute to find_all. + # This will match tags that have that attribute set to any value. + tree = self.soup("""ID present. + No ID present. + ID is empty.""") + self.assertSelects( + tree.find_all(id=True), ["ID present.", "ID is empty."]) + + def test_find_all_with_numeric_attribute(self): + # If you search for a number, it's treated as a string. + tree = self.soup("""Unquoted attribute. + Quoted attribute.""") + + expected = ["Unquoted attribute.", "Quoted attribute."] + self.assertSelects(tree.find_all(id=1), expected) + self.assertSelects(tree.find_all(id="1"), expected) + + def test_find_all_with_list_attribute_values(self): + # You can pass a list of attribute values instead of just one, + # and you'll get tags that match any of the values. + tree = self.soup("""1 + 2 + 3 + No ID.""") + self.assertSelects(tree.find_all(id=["1", "3", "4"]), + ["1", "3"]) + + def test_find_all_with_regular_expression_attribute_value(self): + # You can pass a regular expression as an attribute value, and + # you'll get tags whose values for that attribute match the + # regular expression. + tree = self.soup("""One a. + Two as. + Mixed as and bs. + One b. + No ID.""") + + self.assertSelects(tree.find_all(id=re.compile("^a+$")), + ["One a.", "Two as."]) + + def test_find_by_name_and_containing_string(self): + soup = self.soup("foobarfoo") + a = soup.a + + self.assertEqual([a], soup.find_all("a", text="foo")) + self.assertEqual([], soup.find_all("a", text="bar")) + self.assertEqual([], soup.find_all("a", text="bar")) + + def test_find_by_name_and_containing_string_when_string_is_buried(self): + soup = self.soup("foofoo") + self.assertEqual(soup.find_all("a"), soup.find_all("a", text="foo")) + + def test_find_by_attribute_and_containing_string(self): + soup = self.soup('foofoo') + a = soup.a + + self.assertEqual([a], soup.find_all(id=2, text="foo")) + self.assertEqual([], soup.find_all(id=1, text="bar")) + + + + +class TestIndex(TreeTest): + """Test Tag.index""" + def test_index(self): + tree = self.soup("""
+ Identical + Not identical + Identical + + Identical with child + Also not identical + Identical with child +
""") + div = tree.div + for i, element in enumerate(div.contents): + self.assertEqual(i, div.index(element)) + self.assertRaises(ValueError, tree.index, 1) + + +class TestParentOperations(TreeTest): + """Test navigation and searching through an element's parents.""" + + def setUp(self): + super(TestParentOperations, self).setUp() + self.tree = self.soup(''' +