
from tempfile import mktemp
from unittest import TestCase, main
from os.path import dirname

from micronota.bfillings.util import _get_data_dir
from micronota.db.tigrfam import prepare_metadata


class TigrfamTests(TestCase):
    def setUp(self):
        self.obs_db_fp = mktemp()
        self.exp_db_fp = _get_data_dir()('tigrfam.db')
        self.d = dirname(self.exp_db_fp)

    def test_prepare_metadata(self):
        prepare_metadata(self.d, self.obs_db_fp)
        with open(self.obs_db_fp, 'rb') as o, open(self.exp_db_fp, 'rb') as e:
            self.assertEqual(o.read(), e.read())

if __name__ == '__main__':
    main()


from tempfile import mktemp
from unittest import TestCase, main
from os.path import dirname
from sqlite3 import connect

from micronota.bfillings.util import _get_data_dir
from micronota.db.tigrfam import prepare_metadata


class TigrfamTests(TestCase):
    def setUp(self):
        self.obs_db_fp = mktemp()
        self.exp_db_fp = _get_data_dir()('tigrfam.db')
        self.d = dirname(self.exp_db_fp)

    def test_prepare_metadata(self):
        prepare_metadata(self.d, self.obs_db_fp)
        with connect(self.obs_db_fp) as o, connect(self.exp_db_fp) as e:
            co = o.cursor()
            co.execute('SELECT * from tigrfam')
            ce = e.cursor()
            ce.execute('SELECT * from tigrfam')
            self.assertCountEqual(co.fetchall(), ce.fetchall())

if __name__ == '__main__':
    main()

Update the equality test for database files
Update the equality test for database files

  
  from tempfile import mktemp
  from unittest import TestCase, main
  from os.path import dirname
+ from sqlite3 import connect
  
  from micronota.bfillings.util import _get_data_dir
  from micronota.db.tigrfam import prepare_metadata
  
  
  class TigrfamTests(TestCase):
      def setUp(self):
          self.obs_db_fp = mktemp()
          self.exp_db_fp = _get_data_dir()('tigrfam.db')
          self.d = dirname(self.exp_db_fp)
  
      def test_prepare_metadata(self):
          prepare_metadata(self.d, self.obs_db_fp)
-         with open(self.obs_db_fp, 'rb') as o, open(self.exp_db_fp, 'rb') as e:
+         with connect(self.obs_db_fp) as o, connect(self.exp_db_fp) as e:
+             co = o.cursor()
+             co.execute('SELECT * from tigrfam')
+             ce = e.cursor()
+             ce.execute('SELECT * from tigrfam')
-             self.assertEqual(o.read(), e.read())
+             self.assertCountEqual(co.fetchall(), ce.fetchall())
  
  if __name__ == '__main__':
      main()
  
Update the equality test for database files
## Code Before:

from tempfile import mktemp
from unittest import TestCase, main
from os.path import dirname

from micronota.bfillings.util import _get_data_dir
from micronota.db.tigrfam import prepare_metadata


class TigrfamTests(TestCase):
    def setUp(self):
        self.obs_db_fp = mktemp()
        self.exp_db_fp = _get_data_dir()('tigrfam.db')
        self.d = dirname(self.exp_db_fp)

    def test_prepare_metadata(self):
        prepare_metadata(self.d, self.obs_db_fp)
        with open(self.obs_db_fp, 'rb') as o, open(self.exp_db_fp, 'rb') as e:
            self.assertEqual(o.read(), e.read())

if __name__ == '__main__':
    main()

## Instruction:
Update the equality test for database files
## Code After:

from tempfile import mktemp
from unittest import TestCase, main
from os.path import dirname
from sqlite3 import connect

from micronota.bfillings.util import _get_data_dir
from micronota.db.tigrfam import prepare_metadata


class TigrfamTests(TestCase):
    def setUp(self):
        self.obs_db_fp = mktemp()
        self.exp_db_fp = _get_data_dir()('tigrfam.db')
        self.d = dirname(self.exp_db_fp)

    def test_prepare_metadata(self):
        prepare_metadata(self.d, self.obs_db_fp)
        with connect(self.obs_db_fp) as o, connect(self.exp_db_fp) as e:
            co = o.cursor()
            co.execute('SELECT * from tigrfam')
            ce = e.cursor()
            ce.execute('SELECT * from tigrfam')
            self.assertCountEqual(co.fetchall(), ce.fetchall())

if __name__ == '__main__':
    main()
