コード例 #1
0
def test__populate_plant(elem1, plant1):

    # Tests populate_xml method of Plant class
    act_plant = Plant()
    act_plant.populate_xml(elem1)

    assert_plant(plant1, act_plant)

    return
コード例 #2
0
    def plant_attributes(self, name_num):

        import xml.etree.ElementTree as etree

        # Searches XML for exact match on name_num and returns fully populated Plant object
        # Arguments:
        # name_num - plant name_num to be found
        # Returns - A Plant objects populated with attributes

        found = False

        for event, elem in etree.iterparse(self.xml_file_name, events=("start", "end")):

            if event == "start" and elem.tag == 'EntityDetailsItems':

                plant_elem = elem

                # Start of a plant - compare name numbers and if right one populate object

                if plant_elem.attrib['Name_Num'] == str(name_num):

                    found = True
                    plant = Plant()
                    plant.populate_xml(plant_elem)

            elif event =='end':

                if elem.tag == 'CommonName' or elem.tag == 'Synonyms':

                    # If plant has been found, populate the common names and synonyms
                    if found:
                        if elem.tag == 'CommonName' and elem.text:
                            plant.common_names.append(elem.text)
                        elif elem.tag == 'Synonyms' and elem.text:
                            plant.synonyms.append(elem.text)

                elif elem.tag == 'EntityDetailsItems':

                    # End of a plant
                    if found:
                        if plant.synonyms:
                            # Delete extra synonym generated by extra XML tag
                            del plant.synonyms[-1]

                        break

                # Clear the element to save memory
                elem.clear()
                plant_elem.clear()

        return plant
コード例 #3
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def test_get_plant_attributes(plant1, plant2):

    # Tests data access layer method get_plant_attributes
    # This test uses the real xml file

    act_plant = db.get_plant_attributes('greater quaking grass')

    assert_plant(act_plant, plant1)

    act_plant = db.get_plant_attributes('white bachelor\'s buttons')

    assert_plant(act_plant, plant2)

    act_plant = db.get_plant_attributes('not a real plant')

    assert_plant(act_plant, Plant())

    return
コード例 #4
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant3():

    plant = Plant()

    plant.name_num = '72209'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/WSY0052080_5834.jpg'
    plant.height = '0.1-0.5 metres'
    plant.hardiness = 'H7 (very hardy)'
    plant.common_name = 'plantain lily \'Zounds\''
    plant.spread = '0.5-1 metres'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = '<em>Hosta</em> \'Zounds\''
    plant.description = '\'Zounds\' makes a compact mound of puckered, broadly ovate, golden yellow leaves to 25cm ' \
                        'long, with very pale purple flowers in mid summer'
    plant.soil_type = 'Clay or Loam'
    plant.foliage = 'Deciduous'
    plant.uses = 'City/Courtyard Gardens, Coastal, Cottage/Informal Garden, Flower borders and beds, Ground Cover or ' \
                 'Underplanting of Roses and Shrubs'
    plant.aspect = 'East-facing or North-facing'
    plant.flower_colour = 'Pale Purple in Summer'
    plant.moisture = 'Moist but well-drained'
    plant.ph = 'Acid or Neutral'
    plant.disease_resistance = 'May be subject to <a href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=188\' ' \
                               '>a virus</a>'
    plant.sunlight = 'Partial Shade'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Grow in fertile, moist but well-drained soil with shelter from cold, dry winds. ' \
                        'Best in slightly acid or neutral soils; it will grow in alkaline soils if enriched but ' \
                        'shallow, chalky soils can cause leaves to yellow. Partial shade is best but it can ' \
                        'tolerate some sun if the soil is kept moist. Mulch in spring'
    plant.low_maintenance = 'False'


    return plant
コード例 #5
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant2():

    plant = Plant()

    plant.name_num = '97224'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/WSY0034793_4502.jpg'
    plant.height = '0.5-1 metres'
    plant.hardiness = 'H7 (very hardy)'
    plant.common_name = 'white bachelor\'s buttons'
    plant.spread = '0.1-0.5 metres'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = '<em>Ranunculus</em> <em>aconitifolius</em> \'Flore Pleno\' (d) AGM'
    plant.description = '\'Flore Pleno\' is a vigorous herbaceous perennial to 90cm, with palmately divided dark ' \
                        'green leaves and branched stems bearing long-lasting double, button-like white ' \
                        'flowers 2cm in width'
    plant.soil_type = 'Clay, Loam or Chalk'
    plant.foliage = 'Deciduous'
    plant.uses = 'Cottage/Informal Garden, Flower borders and beds or Cut Flowers'
    plant.aspect = 'South-facing, East-facing or West-facing'
    plant.flower_colour = 'White in Spring and  Summer'
    plant.moisture = 'Moist but well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = 'May be subject to <a ' \
                                       'href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=253\' >powdery ' \
                                       'mildews</a> in dry conditions'
    plant.sunlight = 'Full Sun, Partial Shade'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Grow in humus-rich, fertile, moist or moist but well-drained soil in full or partial shade'
    plant.low_maintenance = 'False'

    plant.common_names.append('fair maids of France')
    plant.common_names.append('fair maids of Kent')
    plant.synonyms.append('<em>Ranunculus</em> <em>aconitifolius</em>  <em>'
                          'flore</em>  <em>pleno</em> \'Batchelor\'s Button\'')

    return plant
コード例 #6
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant7():

    plant = Plant()

    plant.name_num = '100980'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/RHS_PUB0001908_11407.JPG'
    plant.height = '0.1-0.5 metres'
    plant.hardiness = 'H5 (hardy - cold winter)'
    plant.common_name = 'tulip Violacea Group fair'
    plant.spread = '0-0.1 metre'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = '<em>Tulipa</em> <em>humilis</em> Violacea Group (15)'
    plant.description = 'Violacea Group are dwarf perennial bulbs, to 15cm tall, with narrow grey-green leaves. Flowers, pink-purple with a yellow base, appear in late spring'
    plant.soil_type = 'Loam, Chalk or Sand'
    plant.foliage = 'Deciduous'
    plant.uses = 'City/Courtyard Gardens, Cottage/Informal Garden, Flower borders and beds, Patio/Container Plants, Rock Garden or Wildflower meadow'
    plant.aspect = 'South-facing, West-facing or East-facing'
    plant.flower_colour = 'Purple, Yellow and  Dark Pink in Spring'
    plant.moisture = 'Well-drained'
    plant.ph = 'Neutral or Alkaline'
    plant.disease_resistance = 'May be subject to <a href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=252\' ' \
                               '>tulip fire</a>, <a href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=254\' ' \
                               '>tulip viruses</a> and bulb rots'
    plant.sunlight = 'Full Sun'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Plant 10-15cm deep in fertile, well-drained soil in full sun, protect from excessive wet ' \
                        'and shelter from strong winds, see <a href=\'http://www.rhs.org.uk/advicesearch/' \
                        'Profile.aspx?pid=684\' >tulip cultivation</a>'
    plant.low_maintenance = 'False'

    plant.synonyms.append('<em>Tulipa</em> <em>humilis</em> purple')
    plant.synonyms.append('<em>Tulipa</em> <em>pulchella</em> \'Violacea\'')
    plant.synonyms.append('<em>Tulipa</em> <em>violacea</em>')

    return plant
コード例 #7
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant6():

    plant = Plant()

    plant.name_num = '7704'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/WSY0034793_4502.jpg'
    plant.height = '0.5-1 metres'
    plant.hardiness = 'H7 (very hardy)'
    plant.common_name = 'PCN2'
    plant.spread = '0.1-0.5 metres'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = 'ABN2'
    plant.description = 'PCN2 Description'
    plant.soil_type = 'Clay, Loam or Chalk'
    plant.foliage = 'Deciduous'
    plant.uses = 'Cottage/Informal Garden, Flower borders and beds or Cut Flowers'
    plant.aspect = 'South-facing, East-facing or West-facing'
    plant.flower_colour = 'White in Spring and  Summer'
    plant.moisture = 'Moist but well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = ''
    plant.sunlight = 'Full Sun, Partial Shade'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Grow in humus-rich, fertile, moist or moist but well-drained soil in full or partial shade'
    plant.low_maintenance = 'False'

    plant.common_names.append('Potato')
    plant.synonyms.append('<em>Ranunculus</em> <em>aconitifolius</em>  <em>'
                          'flore</em>  <em>pleno</em> \'Batchelor\'s Button\'')

    return plant
コード例 #8
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant1():

    plant = Plant()

    plant.name_num = '76294'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/WSY0035651_4061.jpg'
    plant.height = '0.5-1 metres'
    plant.hardiness = 'H6 (hardy - very cold winter)'
    plant.common_name = 'greater quaking grass'
    plant.spread = '0.1-0.5 metres'
    plant.time_to_full_height = '1-2 years'
    plant.accepted_botanical_name = '<em>Briza</em> <em>maxima</em>'
    plant.description = '<em>B. maxima</em> is an erect annual grass to 60cm, forming a ' \
                                       'tuft of flat, linear leaves, with panicles of large, flat, ovate, pale yellow' \
                                       ' spikelets which dangle from slender branches'
    plant.soil_type = 'Loam, Chalk, Sand or Clay'
    plant.foliage = 'Deciduous'
    plant.uses = 'City/Courtyard Gardens, Cottage/Informal Garden, Flower borders and beds, ' \
                                        'Cut Flowers or Low Maintenance'
    plant.aspect = 'South-facing, North-facing, West-facing or East-facing'
    plant.flower_colour = 'Pale Yellow in Summer'
    plant.moisture = 'Well-drained or Moist but well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = 'Generally disease free'
    plant.sunlight = 'Full Sun'
    plant.exposure = 'Exposed or Sheltered'
    plant.cultivation = 'Easy to grow in most well-drained fertile soils in a sunny position'
    plant.low_maintenance = 'False'

    plant.common_names.append('great quaking grass')
    plant.common_names.append('pearl grass')
    plant.synonyms.append('<em>Briza</em> <em>major</em>')

    return plant
コード例 #9
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant5():

    plant = Plant()

    plant.name_num = '59261'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/WSY0035550_4408.jpg'
    plant.height = '1-1.5 metres'
    plant.hardiness = 'H7 (very hardy)'
    plant.common_name = 'globe thistle \'Taplow Blue\''
    plant.spread = '0.5-1 metres'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = '<em>Echinops</em> <em>bannaticus</em> \'Taplow Blue\''
    plant.description = '\'Taplow Blue\' is a robust, upright herbaceous perennial, with divided, prickly dark ' \
                        'green leaves whitish beneath. Rounded, steel-blue flower heads on branched, leafy stems'
    plant.soil_type = 'Sand, Loam or Chalk'
    plant.foliage = 'Deciduous'
    plant.uses = 'Cottage/Informal Garden, Flower borders and beds, Cut Flowers, Wildlife Gardens, Gravel ' \
                 'Garden or Low Maintenance'
    plant.aspect = 'South-facing, East-facing or West-facing'
    plant.flower_colour = 'Blue in Summer'
    plant.moisture = 'Well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = 'Generally disease free'
    plant.sunlight = 'Full Sun, Partial Shade'
    plant.exposure = 'Exposed'
    plant.cultivation = 'Best in poor, well-drained soil in full sun but will tolerate most soils in full sun and ' \
                        'can tolerate partial shade'
    plant.low_maintenance = 'False'

    plant.synonyms.append('<em>Echinops</em> <em>ritro</em> \'Taplow Blue\'')
    plant.synonyms.append('<em>Echinops</em> \'Taplow Blue\'')
    plant.synonyms.append('<em>Eryngium</em> \'Taplow Blue\'')

    return plant
コード例 #10
0
ファイル: test_data_access.py プロジェクト: annie917/COMM002
def plant4():

    plant = Plant()

    plant.name_num = '311173'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/RHS_RHS-0004192_7162.JPG'
    plant.height = '0.5-1 metres'
    plant.hardiness = 'H2 (tender - cool or frost-free greenhouse)'
    plant.common_name = 'marguerite [LaRita White Beauty]'
    plant.spread = '0.5-1 metres'
    plant.time_to_full_height = '1-2 years'
    plant.accepted_botanical_name = '<em>Argyranthemum</em> <span style="font-variant: small-caps">LaRita White ' \
                                    'Beauty</span> \'Kleaf07028\' (LaRita Series) AGM'
    plant.description = '<span style="font-variant: small-caps">LaRita White Beauty</span> forms a mound to 50 x 60 cm ' \
                        'with silvery glaucous foliage and classic white-rayed, yellow-centred flowers to 4.5cm'
    plant.soil_type = 'Sand, Clay or Loam'
    plant.foliage = 'Evergreen'
    plant.uses = 'City/Courtyard Gardens, Coastal, Flower borders and beds, Patio/Container Plants, Mediterranean ' \
                 'Climate Plants or Wall-side Borders'
    plant.aspect = 'South-facing or East-facing'
    plant.flower_colour = 'White and  Yellow in Autumn, Spring and  Summer'
    plant.moisture = 'Well-drained or Moist but well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = 'Crown gall is an occasional problem'
    plant.sunlight = 'Full Sun'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Grow in moderately fertile, well-drained soil in full sun.  Deadhead regularly to prolong ' \
                        'flowering and pinch growing tips to keep compact. Mulching may protect rootstock from frost, ' \
                        'and helps to conserve water. Water in prolonged dry spells'
    plant.low_maintenance = 'False'

    plant.common_names.append('marguerite \'Kleaf07028\'')

    return plant
コード例 #11
0
    def plants(self, search_string, n):

        import xml.etree.ElementTree as etree

        # Examines the PreferredCommonName, AcceptedBotanicalName, CommonName and Synonyms fields for the search string
        # and returns a list of n Plant objects populated with the attributes of the first n matches
        # Arguments:
        # search_string - string to be matched
        # n - maximum required number of plants, 0 returns all
        # Returns - A list of max n Plant objects, populated with attributes

        s = search_string.lower()
        plants = []
        found = False

        for event, elem in etree.iterparse(self.xml_file_name, events=("start", "end")):

            if event == "start" and elem.tag == 'EntityDetailsItems':

                plant_elem = elem

                # Start of a plant - check relevant attributes

                if s in plant_elem.attrib['PreferredCommonName'].lower() or \
                        s in plant_elem.attrib['AcceptedBotanicalName'].lower():
                    plant = Plant()
                    plant.populate_xml(plant_elem)

                    found = True

            elif event == 'end':

                if elem.tag == 'CommonName' or elem.tag == 'Synonyms':

                    # Only check common names and synonyms if attributes didn't match
                    if not found:
                        if elem.text:
                            if s in elem.text.lower():
                                plant = Plant()
                                plant.populate_xml(plant_elem)
                                found = True

                    # If plant has been stored, add any common names and synonyms
                    if found:
                        if elem.tag == 'CommonName' and elem.text:
                            plant.common_names.append(elem.text)
                        elif elem.tag == 'Synonyms' and elem.text:
                            plant.synonyms.append(elem.text)

                elif elem.tag == 'EntityDetailsItems':

                    # End of a plant
                    # Break if we have enough records, else reset found
                    if found:
                        if plant.synonyms:
                            # Delete extra synonym generated by extra XML tag
                            del plant.synonyms[-1]

                        plants.append(plant)

                        if (len(plants) >= int(n)) and (n != '0'):
                            break
                        else:
                            found = False

                # Clear the element to save memory
                elem.clear()
                plant_elem.clear()

        return plants
コード例 #12
0
def plant7():

    plant = Plant()

    plant.name_num = '18556'
    plant.pic = 'http://vsorchard/PlantFinderPlus_Test/PlantEntityImages/MAR0034393_10079.jpg'
    plant.height = '0.1-0.5 metres'
    plant.hardiness = 'H6 (hardy - very cold winter)'
    plant.preferred_common_name = 'Vvedensky\'s tulip'
    plant.spread = '0.1-0.5 metres'
    plant.time_to_full_height = '2-5 years'
    plant.accepted_botanical_name = '<em>Tulipa</em> <em>vvedenskyi</em> (15)'
    plant.description = '<em>T. vvedenskyi</em> is a perennial bulb to 40cm tall with narrow, wavy-edged, grey-green, ' \
                        'often prostrate, leaves. The red to orange-red flowers reach up to 10.5cm long, with each ' \
                        'petal marked yellow at the base'
    plant.soil_type = 'Loam, Sand or Chalk'
    plant.foliage = 'Deciduous'
    plant.uses = 'Patio/Container Plants, Gravel Garden, Rock Garden, City/Courtyard Gardens or Cottage/Informal Garden'
    plant.aspect = 'South-facing or West-facing'
    plant.flower_colour = 'Red, Yellow and  Dark Orange in Spring'
    plant.moisture = 'Well-drained'
    plant.ph = 'Acid, Alkaline or Neutral'
    plant.disease_resistance = 'May be subject to <a href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=252\' >' \
                               'tulip fire</a> and bulb rots'
    plant.sunlight = 'Full Sun'
    plant.exposure = 'Sheltered'
    plant.cultivation = 'Needs a warm, sunny position with sharp drainage and protection from excessive wet, summer or ' \
                        'winter. See <a href=\'http://www.rhs.org.uk/advicesearch/Profile.aspx?pid=684\' ' \
                        '>tulip cultivation</a>'
    plant.low_maintenance = 'False'

    plant.synonyms.append('<em>Tulipa</em> <em>wedenskyi</em>')

    return plant