Python Forum
AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__
#1
I have a file to validate the label
#configmanager.py

class FunctionNode(object):
    def __validate_func_label(self, func_label):
        pattern = re.compile('^fn[1-9][0-9]{0,1}$')
        if not pattern.match(func_label):
            raise Exception(
                f"Invalid value {func_label} for function label in function config.")
and I have to write a test case using Unit Testing. Test case will check if user enters fn is from fn1 to fn99, it will pass. Otherwise if fn out of range such as fn0 or fn100 then it fail. I writed a TestClass that should have passed
#test__validate_func_label.py

import unittest
import re
from configmanager import FunctionNode

class TestValidateFuncLabel(unittest.TestCase): 

    def test_fn_within_range(self):
        res = FunctionNode.__validate_func_label('fnsd1')
        pattern = re.compile('^fn1$')
        self.assertIn(pattern, range('^fn1$', '^fn100$'))



if __name__ == "__main__":
    unittest.main()
But it has raised an error.
Error:
(base) D:\Python>python -u "d:\Python\Analyzer\toshiba\yieldnews\analyzer\test__validate_func_label.py" E ====================================================================== ERROR: test_fn_within_range (__main__.TestValidateFuncLabel) ---------------------------------------------------------------------- Traceback (most recent call last): File "d:\Python\Analyzer\toshiba\yieldnews\analyzer\test__validate_func_label.py", line 8, in test_fn_within_range res = FunctionNode.__validate_func_label('fnsd1') AttributeError: type object 'FunctionNode' has no attribute '_TestValidateFuncLabel__validate_func_label' ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1)
I don't know where am I wrong ? Can you fix it ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: 'DataFrame' object has no attribute 'Articles' Anldra12 5 640 Jun-17-2021, 04:54 PM
Last Post: Larz60+
  AttributeError: 'Node' object has no attribute 'insert' Anldra12 4 653 May-11-2021, 10:12 AM
Last Post: Anldra12
Star Type Error: 'in' object is not callable nman52 3 501 May-01-2021, 11:03 PM
Last Post: nman52
  Python generics: How to infer generic type from class attribute? Thoufak 0 379 Apr-25-2021, 09:31 AM
Last Post: Thoufak
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 1,300 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  AttributeError: 'tuple' object has no attribute 'format' Anldra12 7 2,943 Apr-13-2021, 07:45 AM
Last Post: Anldra12
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 1,973 Mar-25-2021, 06:40 AM
Last Post: ndc85430
  AttributeError: 'Message' object has no attribute 'split' helpme1 2 903 Mar-14-2021, 11:25 AM
Last Post: helpme1
  AttributeError class object has no attribute list object scttfnch 5 651 Feb-24-2021, 10:03 PM
Last Post: scttfnch
  AttributeError: 'NoneType' object has no attribute 'next' loves 2 1,814 Dec-15-2020, 11:30 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020