1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
## #!/usr/bin/env python
# -*- coding: utf-8 -*-
# <sure - utility belt for automated testing in python>
# Copyright (C) <2010-2023> Gabriel Falcão <gabriel@nacaolivre.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import sure
from sure import expect
from sure.magic import is_cpython
# if is_cpython:
# if sure.allows_new_syntax:
# def test_it_works_with_objects():
# ("anything that inherits from object should be patched")
# (4).should.equal(2 + 2)
# "foo".should.equal("f" + ("o" * 2))
# {}.should.be.empty
# def test_shouldnt_overwrite_class_attributes():
# """do not patch already existing class attributes with same name"""
# class Foo(object):
# when = 42
# shouldnt = 43
# bar = "bar"
# Foo.when.should.be.equal(42)
# Foo.shouldnt.should.be.equal(43)
# Foo.bar.should.be.equal("bar")
# Foo.__dict__.should.contain("when")
# Foo.__dict__.should.contain("shouldnt")
# Foo.__dict__.should.contain("bar")
# dir(Foo).should.contain("when")
# dir(Foo).should.contain("shouldnt")
# dir(Foo).should.contain("bar")
# dir(Foo).shouldnt.contain("should")
# def test_shouldnt_overwrite_instance_attributes():
# """do not patch already existing instance attributes with same name"""
# class Foo(object):
# def __init__(self, when, shouldnt, bar):
# self.when = when
# self.shouldnt = shouldnt
# self.bar = bar
# f = Foo(42, 43, "bar")
# f.when.should.be.equal(42)
# f.shouldnt.should.be.equal(43)
# f.bar.should.be.equal("bar")
# f.__dict__.should.contain("when")
# f.__dict__.should.contain("shouldnt")
# f.__dict__.should.contain("bar")
# dir(f).should.contain("when")
# dir(f).should.contain("shouldnt")
# dir(f).should.contain("bar")
# dir(f).shouldnt.contain("should")
# def test_dir_conceals_sure_specific_attributes():
# ("dir(obj) should conceal names of methods that were grafted by sure")
# x = 123
# expect(set(dir(x)).intersection(set(sure.POSITIVES))).to.be.empty
# expect(set(dir(x)).intersection(set(sure.NEGATIVES))).to.be.empty
# TODO
# def test_it_works_with_non_objects():
# ("anything that inherits from non-object should also be patched")
# class Foo:
# pass
# f = Foo()
# f.should.be.a(Foo)
# def test_can_override_properties():
# x =1
# x.should = 2
# assert x.should == 2
|