File: test_shred.py

package info (click to toggle)
finalcif 113%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 42,568 kB
  • sloc: python: 44,669; sh: 79; makefile: 24
file content (83 lines) | stat: -rw-r--r-- 3,201 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import unittest
from pathlib import Path

from finalcif.cif.cif_file_io import CifContainer
from finalcif.tools.shred import ShredCIF


class TestShedCifWithData(unittest.TestCase):

    def setUp(self) -> None:
        self.cif = CifContainer(Path('test-data/p21c.cif'))
        self.shred = ShredCIF(self.cif, ui=None)
        self.outfile_hkl = self.cif.finalcif_file.with_suffix('.hkl')
        self.outfile_res = self.cif.finalcif_file.with_suffix('.res')

    def tearDown(self) -> None:
        self.outfile_hkl.unlink(missing_ok=True)
        self.outfile_res.unlink(missing_ok=True)

    def test_no_shred(self):
        self.assertEqual(self.outfile_hkl.exists(), False)
        self.assertEqual(self.outfile_res.exists(), False)
        self.assertEqual(self.shred._statusbar.current_message, '')

    def test_shred(self):
        self.shred.shred_cif()
        self.assertEqual(self.outfile_res.exists(), True)
        self.assertEqual(self.outfile_hkl.exists(), True)
        self.assertEqual(self.shred._statusbar.current_message,
                         '\nFinished writing data to p21c-finalcif.res \nand p21c-finalcif.hkl.')


class TestShedCifNoData(unittest.TestCase):

    def setUp(self) -> None:
        self.cif = CifContainer(Path('test-data/1000007.cif'))
        self.shred = ShredCIF(self.cif, ui=None)
        self.outfile_hkl = self.cif.finalcif_file.with_suffix('.hkl')
        self.outfile_res = self.cif.finalcif_file.with_suffix('.res')

    def tearDown(self) -> None:
        self.outfile_hkl.unlink(missing_ok=True)
        self.outfile_res.unlink(missing_ok=True)

    def test_no_shred(self):
        self.assertEqual(self.outfile_hkl.exists(), False)
        self.assertEqual(self.outfile_res.exists(), False)
        self.assertEqual(self.shred._statusbar.current_message, '')

    def test_shred(self):
        self.shred.shred_cif()
        self.assertEqual(self.outfile_res.exists(), False)
        self.assertEqual(self.outfile_hkl.exists(), False)
        self.assertEqual(self.shred._statusbar.current_message,
                         'No .res and .hkl file data found!')


class TestExport(unittest.TestCase):

    def setUp(self) -> None:
        self.cif = CifContainer(Path('tests/examples/work/cu_BruecknerJK_153F40_0m.cif'))
        self.outfile_hkl = self.cif.finalcif_file.with_suffix('.hkl')
        self.outfile_res = self.cif.finalcif_file.with_suffix('.res')
        self.shred = ShredCIF(self.cif, ui=None)
        self.shred.shred_cif()

    def tearDown(self):
        self.outfile_hkl.unlink(missing_ok=True)
        self.outfile_res.unlink(missing_ok=True)

    def test_export_hkl(self):
        """
        Shredcif test
        """
        test_res_file = Path('tests/examples/work/test_hkl_file.txt')
        self.assertEqual(test_res_file.read_text().splitlines(keepends=True),
                         self.outfile_hkl.read_text().splitlines(keepends=True))

    def test_export_res(self):
        test_res_file = Path('tests/examples/work/test_res_file.txt')
        self.assertEqual(test_res_file.read_text().splitlines(keepends=True),
                         self.outfile_res.read_text().splitlines(keepends=True))