Answer the question
In order to leave comments, you need to log in
Python. What is the problem with the test?
the end of the file for the test that translates the entered line into a dictionary list and the number of all atoms:
if __name__ == '__main__':
var = 'H2O'
result = MyClass().parse(var)
print(result)
import unittest
from ..Tasks.MoleculeToAtoms import MyClass
class Test_parse(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_parsing(self):
self.assertEqual(MyClass().parse('H2O'), ({'H': 2, 'O': 1}))
self.assertEqual(MyClass().parse('Mg(OH)2'), ({'Mg': 1, 'O': 2, 'H': 2}))
self.assertEqual(MyClass().parse('K4[ON(SO3)2]2'), ({'K': 4, 'O': 14, 'N': 2, 'S': 4}))
Answer the question
In order to leave comments, you need to log in
Hello. You need to create a setup.py file at the root of your project, here is the documentation: https://docs.python.org/3/distutils/setupscript.html
After that, install your package - pip install --editable . (dot at the end). Further in the tests, you can import the package like this:
from tasks import MyClass
kapets .. removing some 2 points solved the issue. but it's still not clear how Python knows that the desired folder is one level higher?
import unittest
from Tasks.MoleculeToAtoms import MyClass
class Test_parse(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_parsing(self):
self.assertEqual(MyClass().parse('H2O'), ({'H': 2, 'O': 1}))
self.assertEqual(MyClass().parse('Mg(OH)2'), ({'Mg': 1, 'O': 2, 'H': 2}))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question