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'
tag are empty-element, just because
+ # they have no contents.
+ self.assertEqual(b"
", xml_br.encode())
+ self.assertEqual(b"
Don't leave me here.
+Don\'t leave!
""" + soup = self.soup(doc) + second_para = soup.find(id='2') + bold = soup.b + + # Move the tag to the end of the second paragraph. + soup.find(id='2').append(soup.b) + + # The tag is now a child of the second paragraph. + self.assertEqual(bold.parent, second_para) + + self.assertEqual( + soup.decode(), self.document_for( + 'Don\'t leave me .
\n' + 'Don\'t leave!here
')) + + def test_replace_with_returns_thing_that_was_replaced(self): + text = "onethree
') + a = soup.a + b = a.contents[0] + # Make it so the tag has two text children. + a.insert(1, "two") + + # Now replace each one with the empty string. + left, right = a.contents + left.replaceWith('') + right.replaceWith('') + + # The tag is still connected to the tree. + self.assertEqual("three", soup.b.string) + + def test_replace_final_node(self): + soup = self.soup("Argh!") + soup.find(text="Argh!").replace_with("Hooray!") + new_text = soup.find(text="Hooray!") + b = soup.b + self.assertEqual(new_text.previous_element, b) + self.assertEqual(new_text.parent, b) + self.assertEqual(new_text.previous_element.next_element, new_text) + self.assertEqual(new_text.next_element, None) + + def test_consecutive_text_nodes(self): + # A builder should never create two consecutive text nodes, + # but if you insert one next to another, Beautiful Soup will + # handle it correctly. + soup = self.soup("Argh!There's no business like show business
") + no, show = soup.find_all('b') + show.replace_with(no) + self.assertEqual( + soup.decode(), + self.document_for( + "There's business like no business
")) + + self.assertEqual(show.parent, None) + self.assertEqual(no.parent, soup.p) + self.assertEqual(no.next_element, "no") + self.assertEqual(no.next_sibling, " business") + + def test_replace_first_child(self): + data = "Unneeded formatting is unneeded
+ """) + tree.em.unwrap() + self.assertEqual(tree.em, None) + self.assertEqual(tree.p.text, "Unneeded formatting is unneeded") + + def test_wrap(self): + soup = self.soup("I wish I was bold.") + value = soup.string.wrap(soup.new_tag("b")) + self.assertEqual(value.decode(), "I wish I was bold.") + self.assertEqual( + soup.decode(), self.document_for("I wish I was bold.")) + + def test_wrap_extracts_tag_from_elsewhere(self): + soup = self.soup("I wish I was bold.") + soup.b.next_sibling.wrap(soup.b) + self.assertEqual( + soup.decode(), self.document_for("I wish I was bold.")) + + def test_wrap_puts_new_contents_at_the_end(self): + soup = self.soup("I like being bold.I wish I was bold.") + soup.b.next_sibling.wrap(soup.b) + self.assertEqual(2, len(soup.b.contents)) + self.assertEqual( + soup.decode(), self.document_for( + "I like being bold.I wish I was bold.")) + + def test_extract(self): + soup = self.soup( + 'Some content. More content.') + + self.assertEqual(len(soup.body.contents), 3) + extracted = soup.find(id="nav").extract() + + self.assertEqual( + soup.decode(), "Some content. More content.") + self.assertEqual(extracted.decode(), ' ') + + # The extracted tag is now an orphan. + self.assertEqual(len(soup.body.contents), 2) + self.assertEqual(extracted.parent, None) + self.assertEqual(extracted.previous_element, None) + self.assertEqual(extracted.next_element.next_element, None) + + # The gap where the extracted tag used to be has been mended. + content_1 = soup.find(text="Some content. ") + content_2 = soup.find(text=" More content.") + self.assertEqual(content_1.next_element, content_2) + self.assertEqual(content_1.next_sibling, content_2) + self.assertEqual(content_2.previous_element, content_1) + self.assertEqual(content_2.previous_sibling, content_1) + + def test_extract_distinguishes_between_identical_strings(self): + soup = self.soup("foobar") + foo_1 = soup.a.string + bar_1 = soup.b.string + foo_2 = soup.new_string("foo") + bar_2 = soup.new_string("bar") + soup.a.append(foo_2) + soup.b.append(bar_2) + + # Now there are two identical strings in the tag, and two + # in the tag. Let's remove the first "foo" and the second + # "bar". + foo_1.extract() + bar_2.extract() + self.assertEqual(foo_2, soup.a.string) + self.assertEqual(bar_2, soup.b.string) + + def test_clear(self): + """Tag.clear()""" + soup = self.soup("String Italicized and another
") + # clear using extract() + a = soup.a + soup.p.clear() + self.assertEqual(len(soup.p.contents), 0) + self.assertTrue(hasattr(a, "contents")) + + # clear using decompose() + em = a.em + a.clear(decompose=True) + self.assertEqual(0, len(em.contents)) + + def test_string_set(self): + """Tag.string = 'string'""" + soup = self.soup("