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 1113021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:47:39+00:00 2026-05-17T02:47:39+00:00

I am trying to do a simple test in Python using ‘ unittest ‘,

  • 0

I am trying to do a simple test in Python using ‘unittest‘, to see if a class throws an exception if it gets an unsuitable input for the constructor. The class looks like this:

class SummaryFormula:
    def __init__( self, summaryFormula):
        self.atoms = {}
        for atom in re.finditer( "([A-Z][a-z]{0,2})(\d*)", summaryFormula):
            symbol = atom.group(1)
            count = atom.group(2)

            if pocet != "":
                self.atoms[ symbol] = int(count)
            else:
                self.atoms[ symbol] = 1

My test is the following:

    class ConstructorTestCase(unittest.TestCase):
      def testEmptyString(self):
        self.assertRaises(TypeError, ukol1.SummaryFormula(), "testtest")

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

All I want is the test to fail, meaning that the exception of unsuitable input for constructor is not handled.

Instead, I get an error: __init__() takes exactly two arguments (1 given).

What am I missing? What is the second argument I should specify?

Also, what type of Error should I use to handle exception that an input not matchable by my regexp was passed to the constructor?

  • 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-17T02:47:40+00:00Added an answer on May 17, 2026 at 2:47 am

    That’s because your class requires a parameter while instantiating the object.

    While you are passing

    ukol1.SummaryFormula()
    

    You should have been passing the parameter summaryFormula to it.

    ukol1.SummaryFormula(someSummaryFormula)
    

    Also the confusion is because your class name is SummaryFormula and the parameter that you pass to __init__ is also SummaryFormula

    Or it should this be

    self.assertRaises(TypeError, ukol1.SummaryFormula, "testtest")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a VERY simple UI in Python using Tkinter. I
I'm trying to do a simple echo app using Python. I want to submit
I'm trying to make simple library blake hash function wrapper using python ctypes from
I am trying to implement a simple websoket server on python, using RFC 6455
When trying to build a simple test program that uses atomic operations, I get
I am trying to use the native PHP function to send a simple test
I'm trying to use the UI-Thread, so I've written a simple test activity. But
I'm getting an InstantiationException when trying to map Date -> Calendar. Simple test follows:
This is for Play! Framework 2.0. I'm trying to write a simple test case
I'm trying to make a very simple OSGi test but I can't get it

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.