Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 957521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:42:59+00:00 2026-05-16T00:42:59+00:00

Here is my class: class ManagementReview(object): Class describing ManagementReview Object. # Class attributes id

  • 0

Here is my class:

class ManagementReview(object):
    """Class describing ManagementReview Object.
    """

    # Class attributes
    id = 0
    Title = 'New Management Review Object'
    fiscal_year = ''
    region = ''
    review_date = ''
    date_completed = ''
    prepared_by = ''

    __goals = [] # List of <ManagementReviewGoals>.
    __objectives = [] # List of <ManagementReviewObjetives>.
    __actions = [] # List of <ManagementReviewActions>.
    __deliverables = [] # List of <ManagementReviewDeliverable>.
    __issues = [] # List of <ManagementReviewIssue>.

    __created = ''
    __created_by = ''
    __modified = ''
    __modified_by = ''


    def __init__(self,Title='',id=0,fiscal_year='',region='',review_date='',
                    date_completed='',prepared_by='',created='',created_by='',
                    modified='',modified_by=''):
        """Instantiate object.
        """
        if id:
            self.setId(id)
        if Title:
            self.setTitle(Title)
        if fiscal_year:
            self.setFiscal_year(fiscal_year)
        if region:
            self.setRegion(region)
        if review_date:
            self.setReview_date(review_date)
        if date_completed:
            # XXX TODO: validation to see if date_completed pattern matches ISO-8601
            self.setDate_completed(date_completed)
        if prepared_by:
            self.setPrepared_by(prepared_by)
        if created:
            # XXX TODO: validation to see if date_completed pattern matches ISO-8601
            self.setCreated(created)
        else:
            self.setCreated(self.getNow())
        if created_by:
            self.setCreated_by(created_by)
        self.__modified = self.getNow()
        if modified_by:
            self.__modified_by = modified_by

    def __str__(self):
        return "<ManagementReview '%s (%s)'>" % (self.Title,self.id)

    def __setattr__(self, name, value): # Override built-in setter
        # set the value like usual and then update the modified attribute too
        object.__setattr__(self, name, value) # Built-in 
        self.__dict__['__modified'] = datetime.now().isoformat()

    def getActions(self):
        return self.__actions

    def addAction(self,mra):
        self.__actions.append(mra)

    def removeAction(self,id):
        pass # XXX TODO

I have this test:

from datetime import datetime
import random
import unittest

from ManagementReview import ManagementReview, ManagementReviewAction

# Default Values for ManagementReviewAction Object Type
DUMMY_ID = 1
DUMMY_ACTION = 'Action 1'
DUMMY_OWNER = 'Owner 1'
DUMMY_TITLE = 'Test MR'

DUMMY_FISCAL_YEAR = '2011'
DUMMY_REGION = 'WO'
DUMMY_REVIEW_DATE = '2009-01-18T10:50:21.766169',
DUMMY_DATE_COMPLETED = '2008-07-18T10:50:21.766169'
DUMMY_PREPARED_BY = 'test user'
DUMMY_CREATED = '2002-07-18T10:50:21.766169'
DUMMY_CREATED_BY = 'test user 2'
DUMMY_MODIFIED = datetime.now().isoformat()
DUMMY_MODIFIED_BY = 'test user 3'

class TestManagementReviewSetAction(unittest.TestCase):

    def setUp(self):
        self.mr = ManagementReview(DUMMY_TITLE,DUMMY_ID,fiscal_year=DUMMY_FISCAL_YEAR,region=DUMMY_REGION,
                                    review_date=DUMMY_REVIEW_DATE,date_completed=DUMMY_DATE_COMPLETED,
                                    prepared_by=DUMMY_PREPARED_BY,created=DUMMY_CREATED,
                                    created_by=DUMMY_CREATED_BY,modified=DUMMY_MODIFIED,
                                    modified_by=DUMMY_MODIFIED_BY)

    def tearDown(self):
        self.mr = None


    def test_add_action(self):
        for i in range(1,11):
            mra = ManagementReviewAction(i,'action '+str(i),'owner '+str(i))
            self.mr.addAction(mra)
        self.assertEqual(len(self.mr.getActions()),10)

    def test_remove_action(self):
        print len(self.mr.getActions())
        for i in range(1,11):
            mra = ManagementReviewAction(i,'action '+str(i),'owner '+str(i))
            self.mr.addAction(mra)
        self.mr.removeAction(3)
        self.assertEqual(len(self.mr.getActions()),9)


if __name__ == '__main__':
    unittest.main()

The first test passes. That is, self.mr.getActions() has 10 actions.

However, when I run the 2nd test, test_remove_action, the value for len(self.mr.getActions()) is 10. At this point, though, it should be 0.

Why is this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:43:00+00:00Added an answer on May 16, 2026 at 12:43 am

    see if you are keeping track of actions in a class attribute of ManagementReview as opposed to an instance attribute

    A class attribute will be something like

    class Spam(object):
        actions = []
    

    and an instance attribute will look something like

    class Spam(object):
        def __init__(self):
            self.actions = []
    

    What happens is that actions = [] is executed when the class is created and all instances of the class share the same list.

    EDIT:
    In light of your update, I can see that this is definitely what is going on

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a multiple inheritance scenario: class A(object): # code for A here
abstract class User { protected $content; // $content object will be assigned here }
I found this code here class Usable; class Usable_lock { friend class Usable; private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
What am I doing wrong here: class Helo { // main: generate some simple
I have such class (sorry about posible mistakes, i'm writing it right here.) Class
template <bool, class t, class u>// why is bool here,class booltype=bool. Are they equivalent?
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have a few classes as shown here public class TrueFalseQuestion implements Question{ static{
Here is my class (product.cs) where is the method to insert the image: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.