Beispiel #1
0
    def test_basic(self):
        result = 5
        result | should.be_integer()
        (1 + 1) | should_not.equal(1)
        "foo" | should.equal('foo')
        len([1, 2, 3]) | should.be_greater_than(2)

        result += 0.5

        result | should.equal(1 / 2 + 5)
        1 | should_not.eq(2)
        # Matchers not requiring a param can skip the call parens
        True | should.be_truthy

        # Check for exceptions with the context manager interface
        with should.throw(TypeError):
            raise TypeError('foo')

        with should.not_raise:  # will report a failure
            fp = open('does-not-exists.txt')

        # Apply our custom logic for a test
        'FooBarBaz' | should.pass_callback(lambda x: x[3:6] == 'Bar')
Beispiel #2
0
 def get_package_manifest(self):
     cmd = 'oc get packagemanifest %s -o "jsonpath={.metadata.name}"' % self.pkgManifest
     manifest = self.cmd.run_check_for_status(cmd, status=self.pkgManifest)
     manifest | should_not.be_equal_to(None)
     manifest | should.equal(self.pkgManifest)
     return manifest
Beispiel #3
0
def then_clean_environment(context):
    """Check that environment has been reset."""
    len(context.resetEnv.getSpaces()) | should.equal(0).described_as(
        "Number of spaces after environment reset is 0.")
Beispiel #4
0
def then_run_deployed(_context):
    global result
    result | should.equal('Success').desc(
        "Application is not reachable in the Run stage.")
def pyshould_test_sample():
    import unittest
    # from pyshould import *
    import pyshould.patch
    from pyshould import should
    result | should.be_integer()
    (1 + 1) | should_not.equal(1)
    "foo" | should.equal('foo')
    len([1, 2, 3]) | should.be_greater_than(2)
    result | should.equal(1 / 2 + 5)
    1 | should_not.eq(2)
    # Matchers not requiring a param can skip the call parens
    True | should.be_truthy
    # Check for exceptions with the context manager interface
    with should.throw(TypeError):
        raise TypeError('foo')
    with should.not_raise:  # will report a failure
        fp = open('does-not-exists.txt')
    # Apply our custom logic for a test
    'FooBarBaz' | should.pass_callback(lambda x: x[3:6] == 'Bar')
    should.be_an_integer.or_string.and_equal(1)
    # (integer) OR (string AND equal 1)
    should.be_an_integer.or_a_float.or_a_string
    # (integer) OR (float) OR (string)
    should.be_an_integer.or_a_string.and_equal_to(10).or_a_float
    # (integer) OR (string AND equal 10) OR (float)
    should.be_an_integer.or_a_string.but_less_than(10)
    # (integer OR string) AND (less than 10)
    # Note: we can use spacing to make them easier to read
    should.be_an_integer.or_a_string.and_equal(0).or_a_float
    # (integer) OR (string AND equal 0) OR (float)
    # Note: in this case we use capitalization to make them more obvious
    should.be_an_integer.Or_a_string.And_equal(1).But_Not_be_a_float
    # ( (integer) OR (string AND equal 1) ) AND (not float)
    # Note: if no matchers are given the last one is used
    should.be_equal_to(10).Or(20).Or(30)
    # (equal 10) OR (equal 20) OR (equal 30)
    # Note: If no combinator is given AND is used by default
    should.integer.greater_than(10).less_than(20)
    # (integer) AND (greater than 10) AND (less than 20)
    # Note: But by using should_either we can set OR as default
    should_either.equal(10).equal(20).equal(30)

    class TestSequenceFunctions1(unittest.TestCase):
        def setUp(self):
            self.seq = list(range(10))

        def test_shuffle(self):
            # make sure the shuffled sequence does not lose any elements
            random.shuffle(self.seq)
            self.seq.sort()
            self.assertEqual(self.seq, list(range(10)))
            # should raise an exception for an immutable sequence
            self.assertRaises(TypeError, random.shuffle, (1, 2, 3))

        def test_choice(self):
            element = random.choice(self.seq)
            a = 10
            a | should.gt(20)

        def test_sample(self):
            with self.assertRaises(ValueError):
                random.sample(self.seq, 20)
            for element in random.sample(self.seq, 5):
                self.assertTrue(element in self.seq)

    unittest.main()
Beispiel #6
0
def then_app_running_stage(context):
    """Check that the app is deployed and running on stage."""
    result = context.result
    result | should.equal('Success').desc(
        "Application is not reachable in the Stage stage.")