File: test_phase.py

package info (click to toggle)
pyxrd 0.8.4-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,848 kB
  • sloc: python: 26,500; sh: 301; makefile: 128
file content (88 lines) | stat: -rw-r--r-- 2,747 bytes parent folder | download | duplicates (3)
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
84
85
86
87
88
#!/usr/bin/python

# coding=UTF-8
# ex:ts=4:sw=4:et=on

# Copyright (c) 2013, Mathijs Dumon
# All rights reserved.
# Complete license can be found in the LICENSE file.

import unittest

from test.utils import create_object_attribute_test

from pyxrd.data import settings

from pyxrd.phases.models import Phase
from pyxrd.file_parsers.phase_parsers import JSONPhaseParser

__all__ = [
    'TestPhase',
]

class TestPhase(unittest.TestCase):

    phase = None

    def setUp(self):
        settings.initialize()
        self.phase = Phase(R=0, G=1)

    def tearDown(self):
        del self.phase

    def test_not_none(self):
        self.assertIsNotNone(self.phase)

    def test_data_object(self):
        self.assertIsNotNone(self.phase.data_object)

    def test_R_G(self):
        self.assertIsNotNone(Phase(R=0, G=1))
        self.assertIsNotNone(Phase(R=0, G=2))
        self.assertIsNotNone(Phase(R=0, G=3))
        self.assertIsNotNone(Phase(R=0, G=4))
        self.assertIsNotNone(Phase(R=0, G=5))
        self.assertIsNotNone(Phase(R=0, G=6))

        self.assertIsNotNone(Phase(R=1, G=2))
        self.assertIsNotNone(Phase(R=1, G=3))
        self.assertIsNotNone(Phase(R=1, G=4))

        self.assertIsNotNone(Phase(R=2, G=2))
        self.assertIsNotNone(Phase(R=2, G=3))

        self.assertIsNotNone(Phase(R=3, G=2))

    test_name = create_object_attribute_test("phase", "name", "Test Name")
    test_display_color = create_object_attribute_test("phase", "display_color", "#FF00FF")
    test_default_c = create_object_attribute_test("phase", "default_c", 0.646)
    test_sigma_star = create_object_attribute_test("phase", "sigma_star", 12.5)
    test_inherit_display_color = create_object_attribute_test("phase", "inherit_display_color", True)
    test_inherit_CSDS_distribution = create_object_attribute_test("phase", "inherit_CSDS_distribution", True)
    test_inherit_sigma_star = create_object_attribute_test("phase", "inherit_sigma_star", True)
    test_inherit_probabilities = create_object_attribute_test("phase", "inherit_probabilities", True)

    def test_import_export(self):
        from io import BytesIO
        phases = [Phase(R=0, G=1), Phase(R=1, G=2)]
        fn = BytesIO()
        Phase.save_phases(phases, filename=fn)
        loaded_phases = list(JSONPhaseParser.parse(fn))

        def strip_uuid(data):
            new_data = []
            for line in data.split('\n'):
                if "uuid" not in line:
                    new_data.append(line)
            return "\n".join(new_data)

        outp1 = [strip_uuid(phase.dump_object()) for phase in phases]
        outp2 = [strip_uuid(phase.dump_object()) for phase in loaded_phases]
        self.assertEqual(outp1, outp2)





    pass # end of class