How to use set_another_attr method in Testify

Best Python code snippet using Testify_python

test_fixtures_test.py

Source:test_fixtures_test.py Github

copy

Full Screen

...282 def make_sure_i_ran(self):283 assert self.foo_ran284class NewerFixtureMixin(object):285 @class_setup286 def set_another_attr(cls):287 assert cls.foo # this setup should run after FixtureMixin's288 cls.bar = True289 def test_bar(self):290 self.bar_ran = self.bar291class TestFixtureMixinOrder(TestCase, NewerFixtureMixin, FixtureMixin):292 @class_teardown293 def make_sure_i_ran(self):294 assert self.foo_ran295 assert self.bar_ran296class DeprecatedFixtureOrderTestBase(TestCase):297 @class_setup298 def set_something(self):299 assert not hasattr(self, 'something')300 self.something = True...

Full Screen

Full Screen

test_attribute.py

Source:test_attribute.py Github

copy

Full Screen

1#!/usr/bin/python32"""Test module of the data module of BrFAST."""3import unittest4from brfast.data.attribute import Attribute, AttributeSet, DuplicateAttributeId5from tests.data import ATTRIBUTES6class TestAttribute(unittest.TestCase):7 def setUp(self):8 self._attribute_id, self._name = 5, 'user_agent'9 self._attribute = Attribute(self._attribute_id, self._name)10 def test_init(self):11 self.assertEqual(self._attribute.attribute_id, self._attribute_id)12 self.assertEqual(self._attribute.name, self._name)13 def test_repr(self):14 self.assertIsInstance(f'{self._attribute}', str)15 def test_read_only_properties(self):16 with self.assertRaises(AttributeError):17 self._attribute.attribute_id = 718 with self.assertRaises(AttributeError):19 self._attribute.name = 'screen_width'20 def test_equality_new_attribute_same_id_name(self):21 # Another attribute object with the same id / name22 new_attribute = Attribute(self._attribute_id, self._name)23 self.assertEqual(new_attribute, self._attribute)24 self.assertTrue(self._attribute == new_attribute)25 self.assertFalse(self._attribute != new_attribute)26 def test_equality_new_attribute_different_id_name(self):27 # Another attribute object with a different id and name28 other_attribute = Attribute(42, 'unknown')29 self.assertNotEqual(other_attribute, self._attribute)30 self.assertFalse(self._attribute == other_attribute)31 self.assertTrue(self._attribute != other_attribute)32 def test_inequality(self):33 lower_id_attribute = Attribute(1, 'higher_id_attribute')34 higher_id_attribute = Attribute(42, 'higher_id_attribute')35 self.assertTrue(self._attribute > lower_id_attribute)36 self.assertFalse(self._attribute < lower_id_attribute)37 self.assertTrue(higher_id_attribute > self._attribute)38 self.assertFalse(higher_id_attribute < self._attribute)39 def test_inequality_with_integers(self):40 lower_id, higher_id = 1, 4241 with self.assertRaises(TypeError):42 self._attribute > lower_id43 with self.assertRaises(TypeError):44 self._attribute < lower_id45 with self.assertRaises(TypeError):46 higher_id > self._attribute47 with self.assertRaises(TypeError):48 higher_id < self._attribute49 def test_difference_with_integers(self):50 self.assertNotEqual(self._attribute_id, self._attribute)51class TestAttributeSet(unittest.TestCase):52 def setUp(self):53 self._user_agent = ATTRIBUTES[0]54 self._timezone = ATTRIBUTES[1]55 self._do_not_track = ATTRIBUTES[2]56 self._empty_attr_set = AttributeSet()57 self._single_attribute_set = AttributeSet({self._timezone})58 self._attribute_set = AttributeSet({self._user_agent, self._timezone,59 self._do_not_track})60 def test_create_attribute_set_duplicated_id(self):61 duplicated_id_attribute = Attribute(62 self._timezone.attribute_id, 'duplicated_id_attribute')63 with self.assertRaises(DuplicateAttributeId):64 wrong_attribute_set = AttributeSet(65 [self._user_agent, duplicated_id_attribute, self._timezone])66 # NOTE We used a list here as using a set would lead to the67 # duplicated attributes having the same hash as it relies only68 # on the id of the attribute.69 def test_repr(self):70 self.assertIsInstance(repr(self._empty_attr_set), str)71 self.assertIsInstance(repr(self._single_attribute_set), str)72 self.assertIsInstance(repr(self._attribute_set), str)73 def test_len(self):74 self.assertEqual(0, len(self._empty_attr_set))75 self.assertEqual(1, len(self._single_attribute_set))76 self.assertEqual(3, len(self._attribute_set))77 def test_iter(self):78 empty_attributes = [attribute for attribute in self._empty_attr_set]79 self.assertEqual(0, len(empty_attributes))80 single_attributes = [attribute81 for attribute in self._single_attribute_set]82 self.assertEqual(1, len(single_attributes))83 self.assertEqual(self._timezone, single_attributes[0])84 attributes = [attribute for attribute in self._attribute_set]85 self.assertEqual(3, len(attributes))86 self.assertEqual(self._user_agent, attributes[0])87 self.assertEqual(self._timezone, attributes[1])88 self.assertEqual(self._do_not_track, attributes[2])89 def test_attribute_names(self):90 empty_attribute_names = self._empty_attr_set.attribute_names91 self.assertEqual(0, len(empty_attribute_names))92 single_attribute_names = self._single_attribute_set.attribute_names93 self.assertEqual(1, len(single_attribute_names))94 self.assertEqual(self._timezone.name, single_attribute_names[0])95 attribute_names = self._attribute_set.attribute_names96 self.assertEqual(3, len(attribute_names))97 self.assertEqual([self._user_agent.name, self._timezone.name,98 self._do_not_track.name],99 attribute_names)100 def test_attribute_ids(self):101 empty_attribute_ids = self._empty_attr_set.attribute_ids102 self.assertEqual(0, len(empty_attribute_ids))103 single_attribute_ids = self._single_attribute_set.attribute_ids104 self.assertEqual(1, len(single_attribute_ids))105 self.assertEqual(self._timezone.attribute_id, single_attribute_ids[0])106 attribute_ids = self._attribute_set.attribute_ids107 self.assertEqual(3, len(attribute_ids))108 self.assertEqual(109 [self._user_agent.attribute_id, self._timezone.attribute_id,110 self._do_not_track.attribute_id],111 attribute_ids)112 def test_add_new_attribute(self):113 new_attr_set = AttributeSet({self._user_agent})114 self.assertEqual(1, len(new_attr_set))115 new_attribute = ATTRIBUTES[2]116 new_attr_set.add(new_attribute)117 self.assertEqual(2, len(new_attr_set))118 self.assertIn(self._user_agent, new_attr_set)119 self.assertIn(new_attribute, new_attr_set)120 def test_add_new_attribute_already_present(self):121 new_attr_set = AttributeSet({self._user_agent, self._timezone})122 with self.assertRaises(DuplicateAttributeId):123 new_attr_set.add(self._timezone)124 def test_remove(self):125 new_attr_set = AttributeSet({self._user_agent, self._timezone})126 self.assertEqual(2, len(new_attr_set))127 self.assertIn(self._user_agent, new_attr_set)128 self.assertIn(self._timezone, new_attr_set)129 new_attr_set.remove(self._user_agent)130 self.assertEqual(1, len(new_attr_set))131 self.assertIn(self._timezone, new_attr_set)132 self.assertNotIn(self._user_agent, new_attr_set)133 def test_remove_attribute_not_present(self):134 new_attr_set = AttributeSet({self._user_agent, self._timezone})135 self.assertEqual(2, len(new_attr_set))136 self.assertIn(self._user_agent, new_attr_set)137 self.assertIn(self._timezone, new_attr_set)138 non_present_attribute = Attribute(42, 'unknown')139 with self.assertRaises(KeyError):140 new_attr_set.remove(non_present_attribute)141 self.assertEqual(2, len(new_attr_set))142 self.assertIn(self._user_agent, new_attr_set)143 self.assertIn(self._timezone, new_attr_set)144 def test_is_superset(self):145 set_single_attr = AttributeSet({self._user_agent})146 self.assertTrue(self._attribute_set.issuperset(set_single_attr))147 self.assertFalse(set_single_attr.issuperset(self._attribute_set))148 def test_is_superset_empty_set(self):149 self.assertTrue(self._attribute_set.issuperset(self._empty_attr_set))150 self.assertFalse(self._empty_attr_set.issuperset(self._attribute_set))151 def test_is_superset_different_set(self):152 set_another_attr = AttributeSet({Attribute(42, 'unknown'),153 self._user_agent})154 self.assertFalse(set_another_attr.issuperset(self._attribute_set))155 self.assertFalse(self._attribute_set.issuperset(set_another_attr))156 def test_is_subset(self):157 set_single_attr = AttributeSet({self._user_agent})158 self.assertFalse(self._attribute_set.issubset(set_single_attr))159 self.assertTrue(set_single_attr.issubset(self._attribute_set))160 def test_is_subset_empty_set(self):161 self.assertFalse(self._attribute_set.issubset(self._empty_attr_set))162 self.assertTrue(self._empty_attr_set.issubset(self._attribute_set))163 def test_is_subset_different_set(self):164 set_another_attr = AttributeSet({Attribute(42, 'unknown'),165 self._user_agent})166 self.assertFalse(set_another_attr.issubset(self._attribute_set))167 self.assertFalse(self._attribute_set.issubset(set_another_attr))168 def test_get_attribute_by_id(self):169 self.assertEqual(self._user_agent,170 self._attribute_set.get_attribute_by_id(171 self._user_agent.attribute_id))172 self.assertEqual(self._timezone,173 self._attribute_set.get_attribute_by_id(174 self._timezone.attribute_id))175 with self.assertRaises(KeyError):176 self._attribute_set.get_attribute_by_id(-1)177 with self.assertRaises(KeyError):178 self._attribute_set.get_attribute_by_id(0)179 with self.assertRaises(KeyError):180 self._attribute_set.get_attribute_by_id(5)181 def test_get_attribute_by_name(self):182 self.assertEqual(183 self._user_agent,184 self._attribute_set.get_attribute_by_name(self._user_agent.name))185 self.assertEqual(186 self._timezone,187 self._attribute_set.get_attribute_by_name(self._timezone.name))188 with self.assertRaises(KeyError):189 self._attribute_set.get_attribute_by_name('')190 with self.assertRaises(KeyError):191 self._attribute_set.get_attribute_by_name('unknown')192if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful