Python 3 - Assert a boolean.












2















I have overridden __eq___ in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__, I get an error message.



My method:



def __eq__(self, other):
""" Tests if two dual objects are equal or not.

Returns
-------
True or false, depending on the comparison

Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False


In my doctesting file, the following method is meant to test that this method works:



def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y


The error message I get is as follows:



=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""


Is there something I am doing terrifically wrong or overlooking?










share|improve this question























  • error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

    – Sach
    Nov 26 '18 at 8:30
















2















I have overridden __eq___ in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__, I get an error message.



My method:



def __eq__(self, other):
""" Tests if two dual objects are equal or not.

Returns
-------
True or false, depending on the comparison

Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False


In my doctesting file, the following method is meant to test that this method works:



def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y


The error message I get is as follows:



=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""


Is there something I am doing terrifically wrong or overlooking?










share|improve this question























  • error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

    – Sach
    Nov 26 '18 at 8:30














2












2








2








I have overridden __eq___ in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__, I get an error message.



My method:



def __eq__(self, other):
""" Tests if two dual objects are equal or not.

Returns
-------
True or false, depending on the comparison

Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False


In my doctesting file, the following method is meant to test that this method works:



def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y


The error message I get is as follows:



=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""


Is there something I am doing terrifically wrong or overlooking?










share|improve this question














I have overridden __eq___ in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__, I get an error message.



My method:



def __eq__(self, other):
""" Tests if two dual objects are equal or not.

Returns
-------
True or false, depending on the comparison

Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False


In my doctesting file, the following method is meant to test that this method works:



def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y


The error message I get is as follows:



=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""


Is there something I am doing terrifically wrong or overlooking?







python-3.x unit-testing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 3:19









WorkhorseWorkhorse

462511




462511













  • error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

    – Sach
    Nov 26 '18 at 8:30



















  • error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

    – Sach
    Nov 26 '18 at 8:30

















error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

– Sach
Nov 26 '18 at 8:30





error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.

– Sach
Nov 26 '18 at 8:30












1 Answer
1






active

oldest

votes


















0














Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :



assert z.r == y.r
assert z.d == z.d





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474377%2fpython-3-assert-a-boolean%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
    you can do below :



    assert z.r == y.r
    assert z.d == z.d





    share|improve this answer




























      0














      Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
      you can do below :



      assert z.r == y.r
      assert z.d == z.d





      share|improve this answer


























        0












        0








        0







        Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
        you can do below :



        assert z.r == y.r
        assert z.d == z.d





        share|improve this answer













        Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
        you can do below :



        assert z.r == y.r
        assert z.d == z.d






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 8:31









        SachSach

        685517




        685517
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474377%2fpython-3-assert-a-boolean%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'