How to use is_child_of method in assertpy

Best Python code snippet using assertpy_python

test_sysinfo.py

Source:test_sysinfo.py Github

copy

Full Screen

...103class TestSwapArea(unittest.TestCase):104 def test_that_swap_area_is_child_of_partition(self):105 p = Partition("8 2 497660 sda2".split(" "))106 sa = SwapArea("/dev/sda2 partition 497660 0 -1".split(" "))107 self.assertTrue(sa.is_child_of(p))108class TestMountedFileSystem(unittest.TestCase):109 def test_that_mounted_fs_is_not_child_of_wrong_partition(self):110 p = Partition("8 1 1000 sda1".split(" "))111 mfs = MountedFileSystem("/dev/sda2 3897212928 2526269440 1212547072 68% /boot".split(" "))112 self.assertFalse(mfs.is_child_of(p))113 def test_that_mounted_fs_is_child_of_partition(self):114 p = Partition("8 1 1000 sda1".split(" "))115 mfs = MountedFileSystem("/dev/sda1 3897212928 2526269440 1212547072 68% /boot".split(" "))116 self.assertTrue(mfs.is_child_of(p))117 def test_that_mounted_fs_is_child_of_raid_array(self):118 r = RaidArray(("md1 /dev/sda1".split(" "), 1000))119 mfs = MountedFileSystem("/dev/md1 3897212928 2526269440 1212547072 68% /boot".split(" "))120 self.assertTrue(mfs.is_child_of(r))121 def test_that_mounted_fs_is_child_of_lvm_lv_given_vg_matches(self):122 lv = LvmLogicalVolume("small test 1000".split(" "))123 mfs = MountedFileSystem("/dev/mapper/test-small 3897212928 2526269440 1212547072 68% /boot".split(" "))124 self.assertTrue(mfs.is_child_of(lv))125 def test_that_mounted_fs_is_not_child_of_lvm_lv_if_lv_mismatch(self):126 lv = LvmLogicalVolume("big test 1000".split(" "))127 mfs = MountedFileSystem("/dev/mapper/test-small 3897212928 2526269440 1212547072 68% /boot".split(" "))128 self.assertFalse(mfs.is_child_of(lv))129 def test_that_mounted_fs_is_not_child_of_lvm_lv_if_vg_mismatch(self):130 lv = LvmLogicalVolume("small blob 1000".split(" "))131 mfs = MountedFileSystem("/dev/mapper/test-small 3897212928 2526269440 1212547072 68% /boot".split(" "))132 self.assertFalse(mfs.is_child_of(lv))133 def test_that_mounted_fs_is_not_child_of_root(self):134 r = Root()135 mfs = MountedFileSystem("/dev/mapper/test-small 3897212928 2526269440 1212547072 68% /boot".split(" "))136 self.assertFalse(mfs.is_child_of(r))137class TestSysInfoLvmPhysicalVolumeGeneration(unittest.TestCase):138 @patch("diskgraph.sysinfo.checker", checker_mock(True))139 @patch("subprocess.check_output")140 def setUp(self, exec_mock):141 exec_mock.return_value = " /dev/md0 1500310929408\n"142 self.pvs = LvmPhysicalVolume.generate()143 def test_that_one_lvm_physical_volume_is_found(self):144 self.assertEqual(1, len(self.pvs))145 def test_that_lvm_physical_volume_is_of_right_type(self):146 pv = self.pvs[0]147 self.assertIsInstance(pv, LvmPhysicalVolume)148 def test_that_lvm_physical_volume_contains_name(self):149 pv = self.pvs[0]150 self.assertEqual("md0", pv.name)151 def test_that_lvm_physical_volume_contains_size(self):152 pv = self.pvs[0]153 self.assertEqual(1500310929408, pv.byte_size)154class TestSysInfoLvmVolumeGroupGeneration(unittest.TestCase):155 @patch("diskgraph.sysinfo.checker", checker_mock(True))156 @patch("subprocess.check_output")157 def setUp(self, exec_mock):158 exec_mock.return_value = (" backup 700146778112 /dev/md1 0\n"159 " backup 700146778112 /dev/md2 0\n"160 " small 50008686592 /dev/sdd2 0\n")161 self.vgs = LvmVolumeGroup.generate()162 def test_that_two_lvm_volume_groups_are_found(self):163 self.assertEqual(2, len(self.vgs))164 def test_that_lvm_volume_group_is_of_right_type(self):165 vg = self.vgs[0]166 self.assertIsInstance(vg, LvmVolumeGroup)167 def test_that_lvm_volume_group_contains_name(self):168 vg = self.vgs[0]169 self.assertEqual("backup", vg.name)170 def test_that_lvm_volume_group_contains_size(self):171 vg = self.vgs[0]172 self.assertEqual(700146778112, vg.byte_size)173 def test_that_lvm_volume_group_contains_physical_volume_names(self):174 vg = self.vgs[0]175 self.assertListEqual(["md1", "md2"], vg.pv_names)176class TestSysInfoLvmLogicalVolumeGeneration(unittest.TestCase):177 @patch("diskgraph.sysinfo.checker", checker_mock(True))178 @patch("subprocess.check_output")179 def setUp(self, exec_mock):180 exec_mock.return_value = " homes backup 21474836480\n"181 self.lvs = LvmLogicalVolume.generate()182 def test_that_one_lvm_logical_volume_is_found(self):183 self.assertEqual(1, len(self.lvs))184 def test_that_lvm_logical_volume_is_of_right_type(self):185 lv = self.lvs[0]186 self.assertIsInstance(lv, LvmLogicalVolume)187 def test_that_lvm_logical_volume_contains_name(self):188 lv = self.lvs[0]189 self.assertEqual("homes", lv.name)190 def test_that_lvm_logical_volume_contains_size(self):191 lv = self.lvs[0]192 self.assertEqual(21474836480, lv.byte_size)193 def test_that_lvm_logical_volume_contains_volume_group_name(self):194 lv = self.lvs[0]195 self.assertEqual("backup", lv.vg_name)196class TestPartition(unittest.TestCase):197 def test_that_hd_without_number_is_disk(self):198 p = Partition("3 0 1000 hda".split(" "))199 self.assertTrue(p.is_disk())200 def test_that_sd_without_number_is_disk(self):201 p = Partition("8 0 1000 sda".split(" "))202 self.assertTrue(p.is_disk())203 def test_that_hd_with_number_is_not_disk(self):204 p = Partition("3 1 1000 hda1".split(" "))205 self.assertFalse(p.is_disk())206 def test_that_partition_is_part_for_disk(self):207 d = Partition("8 0 1000 sda".split(" "))208 p = Partition("8 1 1000 sda1".split(" "))209 self.assertTrue(p.is_partition_for(d))210 def test_that_partition_is_not_part_for_disk(self):211 d = Partition("8 0 1000 sda".split(" "))212 p = Partition("8 17 1000 sdb1".split(" "))213 self.assertFalse(p.is_partition_for(d))214 def test_that_partition_is_child_of_root_if_disk(self):215 r = Root()216 d = Partition("8 0 1000 sda".split(" "))217 self.assertTrue(d.is_child_of(r))218 def test_that_partition_is_not_child_of_root_if_partition(self):219 r = Root()220 p = Partition("8 1 1000 sda1".split(" "))221 self.assertFalse(p.is_child_of(r))222 def test_that_partition_is_child_of_disk(self):223 d = Partition("8 0 1000 sda".split(" "))224 p = Partition("8 1 1000 sda1".split(" "))225 self.assertTrue(p.is_child_of(d))226class TestLvmPhysicalVolume(unittest.TestCase):227 def test_that_pv_is_child_of_disk_if_name_matches(self):228 d = Partition("8 0 1000 sda".split(" "))229 pv = LvmPhysicalVolume("/dev/sda 1000".split(" "))230 self.assertTrue(pv.is_child_of(d))231 def test_that_pv_is_not_child_of_disk_if_name_doesnt_match(self):232 d = Partition("8 0 1000 sda".split(" "))233 pv = LvmPhysicalVolume("/dev/sdb 1000".split(" "))234 self.assertFalse(pv.is_child_of(d))235 def test_that_pv_is_child_of_partition(self):236 p = Partition("8 1 1000 sda1".split(" "))237 pv = LvmPhysicalVolume("/dev/sda1 1000".split(" "))238 self.assertTrue(pv.is_child_of(p))239 def test_that_pv_is_child_of_raid_array(self):240 r = RaidArray(("md1 /dev/sda1".split(" "), 1000))241 pv = LvmPhysicalVolume("/dev/md1 1000".split(" "))242 self.assertTrue(pv.is_child_of(r))243 def test_that_pv_is_not_child_of_root(self):244 r = Root()245 pv = LvmPhysicalVolume("/dev/sda 1000".split(" "))246 self.assertFalse(pv.is_child_of(r))247class LvmVolumeGroupTest(unittest.TestCase):248 def test_that_vg_is_child_of_pv_if_pv_among_names(self):249 pv = LvmPhysicalVolume("/dev/sda 1000".split(" "))250 vg = LvmVolumeGroup(["test", "1000", ["/dev/sda"], "0"])251 self.assertTrue(vg.is_child_of(pv))252 def test_that_vg_is_not_child_of_pv_if_pv_not_among_names(self):253 pv = LvmPhysicalVolume("/dev/sda 1000".split(" "))254 vg = LvmVolumeGroup(["test", "1000", ["/dev/sdb"], "0"])255 self.assertFalse(vg.is_child_of(pv))256 def test_that_vg_is_not_child_of_root(self):257 r = Root()258 vg = LvmVolumeGroup(["test", "1000", ["/dev/sdb"], "0"])259 self.assertFalse(vg.is_child_of(r))260class LvmLogicalVolumeTest(unittest.TestCase):261 def test_that_lv_is_child_of_vg_with_correct_name(self):262 vg = LvmVolumeGroup(["test", "1000", ["/dev/sdb"], "0"])263 lv = LvmLogicalVolume("small test 1000".split(" "))264 self.assertTrue(lv.is_child_of(vg))265 def test_that_lv_is_not_child_of_vg_with_wrong_name(self):266 vg = LvmVolumeGroup(["blob", "1000", ["/dev/sdb"], "0"])267 lv = LvmLogicalVolume("small test 1000".split(" "))268 self.assertFalse(lv.is_child_of(vg))269 def test_that_lv_is_not_child_of_root(self):270 r = Root()271 lv = LvmLogicalVolume("small test 1000".split(" "))272 self.assertFalse(lv.is_child_of(r))273class RaidArrayTest(unittest.TestCase):274 def test_that_array_is_child_of_disk_among_names(self):275 d = Partition("8 0 1000 /dev/sda".split(" "))276 r = RaidArray(("md1 /dev/sda".split(" "), 1000))277 self.assertTrue(r.is_child_of(d))278 def test_that_array_is_not_child_of_disk_not_among_names(self):279 d = Partition("8 16 1000 /dev/sdb".split(" "))280 r = RaidArray(("md1 /dev/sda".split(" "), 1000))281 self.assertFalse(r.is_child_of(d))282 def test_that_array_is_child_of_partition_among_names(self):283 p = Partition("8 1 1000 /dev/sda1".split(" "))284 r = RaidArray(("md1 /dev/sda1".split(" "), 1000))285 self.assertTrue(r.is_child_of(p))286@patch("diskgraph.sysinfo.checker", checker_mock(False))287class MissingFileOrCommandTest(unittest.TestCase):288 @patch("subprocess.check_output")289 def test_that_no_lvm_physical_volumes_are_found_if_lvm_commands_dont_exist(self, co_mock):290 co_mock.side_effect = CalledProcessError(1, "pvs")291 self.assertEqual(0, len(LvmPhysicalVolume.generate()))292 @patch("subprocess.check_output")293 def test_that_no_lvm_logical_volums_are_found_if_lvm_commands_dont_exist(self, co_mock):294 co_mock.side_effect = CalledProcessError(1, "lvs")295 self.assertEqual(0, len(LvmLogicalVolume.generate()))296 @patch("subprocess.check_output")297 def test_that_no_lvm_volume_groups_are_found_if_lvm_commands_dont_exist(self, co_mock):298 co_mock.side_effect = CalledProcessError(1, "vgs")299 self.assertEqual(0, len(LvmVolumeGroup.generate()))...

Full Screen

Full Screen

11_drugbank.py

Source:11_drugbank.py Github

copy

Full Screen

...20 idx = k = t.rfind("}")21 if idx != -1:22 t = t[idx + 1 :]23 return t24def is_child_of(tag_name, path):25 if len(path) < 1: # if path is less than 1, stop26 return False27 parent = path[-1] # the -1 position in the path is the parent28 # print(parent)29 return tag_name == parent30drugs = etree.iterparse(xml_file, events=("start", "end"))31drug_count = 032name = None33start_time = time.time()34path = [] # create an empty list for the paths to go to35# # set up for writing to csv36with codecs.open(csv_file, "w", encoding) as drugbank_drugs:37 drugs_writer = csv.writer(drugbank_drugs, quoting=csv.QUOTE_MINIMAL)38 drugs_writer.writerow(39 [40 "name",41 "description",42 "state",43 "synonyms",44 "indications",45 "dosages",46 "drug interactions",47 "pathways",48 "target",49 ]50 )51 for event, elem in drugs:52 tag_name = strip_tag_name(elem.tag)53 # # if there is a start event (e.g. <drug>) append the path list up to the tag name54 # e.g. tag_name = name # path = ['drugbank', 'drug', 'name']55 # e.g. tag_name = description # path = ['drugbank', 'drug', 'description']56 if event == "start":57 path.append(tag_name)58 else:59 path.pop() # removes the tag_name at the end e.g. <drug> <name> to just <drug>60 # print(path)61 # # check the start event, reset all the values and then check the end event - if wanted, write element62 if event == "start":63 if tag_name == "drug":64 drug_name = ""65 description = ""66 state = ""67 synonyms = []68 indication = ""69 dosages = []70 drug_interactions = []71 pathways = []72 targets = []73 else: # event == 'end'74 if tag_name == "name":75 if is_child_of(76 "drug", path77 ): # if it is a child of the tag name (e.g. name within drug) then add text78 drug_name = elem.text79 # print(elem.text)80 elif is_child_of("drug-interaction", path):81 drug_interaction_name = elem.text82 elif is_child_of("pathway", path):83 pathway_name = elem.text84 elif tag_name == "description":85 if is_child_of("drug", path):86 description = elem.text87 # print(elem.text)88 elif tag_name == "state":89 state = elem.text90 elif tag_name == "synonym":91 if is_child_of("synonyms", path):92 synonym = elem.text93 elif tag_name == "synonyms":94 synonyms.append(synonym)95 # print(synonyms)96 elif tag_name == "indication":97 indication = elem.text98 # print(elem.text)99 elif tag_name == "form":100 form = elem.text101 # print(elem.text)102 elif tag_name == "route":103 route = elem.text104 # print(elem.text)105 elif tag_name == "strength":...

Full Screen

Full Screen

distdir_test.py

Source:distdir_test.py Github

copy

Full Screen

...8 assert DistDir(relpath=Path("dist")) == validate_distdir(Path("dist"), buildroot)9 assert DistDir(relpath=Path("dist")) == validate_distdir(Path("/buildroot/dist"), buildroot)10 with pytest.raises(InvalidDistDir):11 validate_distdir(Path("/other/dist"), buildroot)12def test_is_child_of() -> None:13 mock_build_root = Path("/mock/build/root")14 assert is_child_of(Path("/mock/build/root/dist/dir"), mock_build_root)15 assert is_child_of(Path("dist/dir"), mock_build_root)16 assert is_child_of(Path("./dist/dir"), mock_build_root)17 assert is_child_of(Path("../root/dist/dir"), mock_build_root)18 assert is_child_of(Path(""), mock_build_root)19 assert is_child_of(Path("./"), mock_build_root)20 assert not is_child_of(Path("/other/random/directory/root/dist/dir"), mock_build_root)...

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 assertpy 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