Best Python code snippet using keyboard
test_molecules_fileIO.py
Source: test_molecules_fileIO.py
1import unittest2import numpy as np3import os4import filecmp5from bumpy import Molecules, Metadata6from tests.testutils import PDBComp, GROComp7referenceFilePath = os.path.join(os.path.dirname(__file__), "reference_files/test_molecules_fileIO/")8class test_read_input(unittest.TestCase):9 # TODO : add checks for ignoring HETATOMS, etc10 def test_argument_sanity_checks(self):11 pass12 def test_read_pdb(self):13 inputPDBPath = referenceFilePath + "read_pdb.pdb"14 testMolecule = Molecules(infile=inputPDBPath)15 # test coordinates16 self.assertEqual(testMolecule.coords.shape, (3, 3))17 self.assertAlmostEqual(testMolecule.coords[0, 0], 0)18 self.assertAlmostEqual(testMolecule.coords[1, 1], -10)19 self.assertAlmostEqual(testMolecule.coords[2, 2], 0.7)20 # test atomnames21 self.assertEqual(testMolecule.metadata.atomname[0].strip(), "A")22 self.assertEqual(testMolecule.metadata.atomname[1].strip(), "B")23 self.assertEqual(testMolecule.metadata.atomname[2].strip(), "A")24 # test resnames25 self.assertEqual(testMolecule.metadata.resname[0], "MOLA")26 self.assertEqual(testMolecule.metadata.resname[1], "MOLA")27 self.assertEqual(testMolecule.metadata.resname[2], "MOLB")28 def test_read_gro(self):29 inputGROPath = referenceFilePath + "read_gro.gro"30 testMolecule = Molecules(infile=inputGROPath)31 # test coordinates32 self.assertEqual(testMolecule.coords.shape, (3, 3))33 self.assertAlmostEqual(testMolecule.coords[0, 0], 0)34 self.assertAlmostEqual(testMolecule.coords[1, 1], -10)35 self.assertAlmostEqual(testMolecule.coords[2, 2], 0.7)36 # test atomnames37 self.assertEqual(testMolecule.metadata.atomname[0].strip(), "A")38 self.assertEqual(testMolecule.metadata.atomname[1].strip(), "B")39 self.assertEqual(testMolecule.metadata.atomname[2].strip(), "A")40 # test resnames41 self.assertEqual(testMolecule.metadata.resname[0], "MOLA")42 self.assertEqual(testMolecule.metadata.resname[1], "MOLA")43 self.assertEqual(testMolecule.metadata.resname[2], "MOLB")44 # TODO: test resnums45 def test_ignore_resnames(self):46 inputPDBPath = referenceFilePath + "read_pdb.pdb"47 testMolecule = Molecules(infile=inputPDBPath, ignore="MOLB")48 self.assertEqual(testMolecule.coords.shape, (2, 3))49 self.assertAlmostEqual(testMolecule.coords[0, 0], 0)50 self.assertAlmostEqual(testMolecule.coords[1, 1], -10)51 # test atomnames52 self.assertEqual(testMolecule.metadata.atomname[0].strip(), "A")53 self.assertEqual(testMolecule.metadata.atomname[1].strip(), "B")54 # test resnames55 self.assertEqual(testMolecule.metadata.resname[0], "MOLA")56 self.assertEqual(testMolecule.metadata.resname[1], "MOLA")57class test_write_coordinates(unittest.TestCase):58 def setUp(self):59 ''' Sets up a molecule with equivalent fields to the reference files used for reading tests. Not just60 loading a molecule directly from file because if the reading gets broken then the writing tests would61 likely break too62 '''63 metadata = Metadata(atomname=np.array(("A", "B", "A"), dtype="<U4"),64 resname=np.array(("MOLA", "MOLA", "MOLB"), dtype="<U4"),65 ressize=np.array((2, 0, 1)))66 coords = np.array([[0.000, -5.000, 0.500],67 [5.000, -10.000, 0.600],68 [10.000, -20.000, 0.700]])69 boxdims = np.array([100, 100, 80])70 self.simple_system = Molecules(metadata=metadata, coords=coords, boxdims=boxdims)71 def tearDown(self):72 ''' Removes temporary files generated during output tests '''73 written_test_files = ["test_write_simple.pdb", "test_write_simple.gro"]74 for file in written_test_files:75 if os.path.exists(file):76 os.remove(file)77 def test_write_pdb(self):78 ''' Want exact match with reference PDB, turn off position changing'''79 temporaryOutputPath = "test_write_simple.pdb"80 self.simple_system.write_coordinates(temporaryOutputPath, position=False, reorder=False)81 self.assertTrue(PDBComp.compareAtomFields(temporaryOutputPath, referenceFilePath + "read_pdb.pdb"))82 def test_write_gro(self):83 ''' Want exact match with reference GRO, turn off position changing'''84 temporaryOutputPath = "test_write_simple.gro"85 self.simple_system.write_coordinates("test_write_simple.gro", position=False, reorder=False)86 self.assertTrue(GROComp.compareAtomFields(temporaryOutputPath, referenceFilePath + "read_gro.gro"))87class test_write_topology(unittest.TestCase):88 def setUp(self):89 metadata = Metadata(atomname=np.array(("A", "A", "B", "B"), dtype="<U4"),90 resname=np.array(("MOLA", "MOLA", "MOLB", "MOLB"), dtype="<U4"),91 ressize=np.array((1, 1, 2, 0)))92 self.simple_system = Molecules(metadata=metadata)93 def tearDown(self):94 ''' Removes temporary files generated during output tests '''95 written_test_files = ["test_write_simple.top"]96 for file in written_test_files:97 if os.path.exists(file):98 os.remove(file)99 def test_basic_functionality(self):100 temporaryOutputPath = "test_write_simple.top"101 self.simple_system.write_topology(temporaryOutputPath)102 self.assertTrue(filecmp.cmp(temporaryOutputPath, referenceFilePath + "reference_basic_top.top"))103class test_write_index(unittest.TestCase):104 def setUp(self):105 metadata = Metadata(atomname=np.array(("A", "A", "B", "B"), dtype="<U4"),106 resname=np.array(("MOLA", "MOLA", "MOLB", "MOLB"), dtype="<U4"),107 leaflets=np.array((0, 1, 1, 1)),108 ressize=np.array((1, 1, 2, 0)))109 self.simple_system = Molecules(metadata=metadata)110 def tearDown(self):111 written_test_files = ["test_write_simple.ndx", "test_write_top_leaflet_only.ndx",112 "test_write_molB_as_dummy.ndx"]113 for file in written_test_files:114 if os.path.exists(file):115 os.remove(file)116 def test_writes_fields(self):117 temporaryOutputPath = "test_write_simple.ndx"118 self.simple_system.write_index(temporaryOutputPath)119 self.assertTrue(filecmp.cmp(temporaryOutputPath, referenceFilePath + "reference_basic_index.ndx"))120 def test_handles_zero_indices(self):121 temporaryOutputPath = "test_write_top_leaflet_only.ndx"122 self.simple_system.metadata.leaflets = np.array((1, 1, 1, 1))123 self.simple_system.write_index(temporaryOutputPath)124 self.assertTrue(filecmp.cmp(temporaryOutputPath, referenceFilePath + "reference_top_index_only.ndx"))125 def test_writes_dummy_particles(self):126 # In this case, we'll just treat MOL B as a dummy particle127 temporaryOutputPath = "test_write_molB_as_dummy.ndx"128 self.simple_system.write_index(temporaryOutputPath, dummy_name="MOLB")129 self.assertTrue(filecmp.cmp(temporaryOutputPath, referenceFilePath + "reference_dummy_index.ndx"))130if __name__ == "__main__":...
test_write.py
Source: test_write.py
1import openmetadata as om2import openmetadata.tests3class TestWrite(openmetadata.tests.DynamicTestCase):4 def test_write_simple(self):5 om.write(self.root_path, 'simple', 'value')6 self.assertEquals(om.read(self.root_path, 'simple'), 'value')7 def test_write_deep(self):8 om.write(self.root_path, '/deep/data/key', 'value')9 self.assertEquals(om.read(self.root_path, '/deep/data/key'), 'value')10 def test_write_invalidgroup(self):11 om.write(self.root_path, '/deep/data.string/key', 'value')...
Check out the latest blogs from LambdaTest on this topic:
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When you hear the term Cross Browser Testing what comes immediately to your mind? Something that decodes the literal meaning i.e. testing for cross-browsers or you can say testing an application across various browsers.
Nowadays, many organizations have software products (websites or apps) that are built for a global audience. One of the trickiest parts is delivering an experience that appeals to the local audience of the target market. Catering to the needs of the local users would require localization. You would have come across internationalization and localization testing when designing for the ‘global and local’ market. There is a difference between internationalization and localization testing since the tests are developed from a different market point of view.
Just earlier this month, Apple officially announced the release of a new range of iPhone flagship models for 2018. The new models named iPhone XS, iPhone XS Max, and iPhone XR comes equipped with a lot of new features, trademark notch, and new headaches for developers. To help developers out, today we brought these new devices on LambdaTest’s cross-browser compatibility testing platform, along with the latest iOS 12 version. In addition, we also bring Mozilla Firefox browsers on the latest Android and iOS devices.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!