Пример #1
0
    def test_that_init_accepts_new_list_elements(self, mock_insert_item):
        new_elements = [
            PeriodicTableItem("H", 1, 1, 1, "hydrogen", 1.00800,
                              "diatomic nonmetal"),
            PeriodicTableItem("He", 2, 18, 1, "helium", 4.0030, "noble gas"),
            PeriodicTableItem("Li", 3, 1, 2, "lithium", 6.94000,
                              "alkali metal")
        ]
        PeriodicCombo(elements=new_elements, detailed=True)
        self.assertEqual(mock_insert_item.call_count, 3)
        mock_insert_item.assert_called_with(2, 'Li (3) - lithium')

        PeriodicCombo(elements=new_elements, detailed=False)
        self.assertEqual(mock_insert_item.call_count, 3 + 3)
        mock_insert_item.assert_called_with(2, 'Li (3)')
Пример #2
0
    def test_that_setSelection_sets_correct_selection_if_given_PeriodicTableItem(
            self):
        combo = PeriodicCombo()
        combo.setCurrentIndex = mock.Mock()
        combo.setSelection(
            PeriodicTableItem("H", 1, 1, 1, "hydrogen", 1.00800,
                              "diatomic nonmetal"))

        combo.setCurrentIndex.assert_called_with(0)
Пример #3
0
class PeriodicTableItemTest(unittest.TestCase):
    def setUp(self):
        self.element = PeriodicTableItem("Ti", 22, 4, 4, "titanium", 47.9000, "transition metal")

    def test_that_given_list_of_elements_contains_all_the_required_fields(self):
        # Check that all elements in the periodic table are provided with all the required fields:
        # Symbol, Atomic Number, Col, Row, Name, Mass, Subcategory
        for i in range(len(periodic_table._elements)-1):
            self.assertTrue(isinstance(periodic_table._elements[i][0], str))
            self.assertTrue(isinstance(periodic_table._elements[i][1], int))
            self.assertTrue(isinstance(periodic_table._elements[i][2], int))
            self.assertTrue(isinstance(periodic_table._elements[i][3], int))
            self.assertTrue(isinstance(periodic_table._elements[i][4], str))
            # For some elements the atomic weight is only approximate and represented as an integer
            self.assertTrue(isinstance(periodic_table._elements[i][5], float)
                            or isinstance(periodic_table._elements[i][5], int))
            self.assertTrue(isinstance(periodic_table._elements[i][6], str))

        # Meitnerium is not confirmed to be a transition metal, hence it lacks the subcategory field (ie. field 6)
        i = len(periodic_table._elements)-1
        self.assertTrue(isinstance(periodic_table._elements[i][0], str))
        self.assertTrue(isinstance(periodic_table._elements[i][1], int))
        self.assertTrue(isinstance(periodic_table._elements[i][2], int))
        self.assertTrue(isinstance(periodic_table._elements[i][3], int))
        self.assertTrue(isinstance(periodic_table._elements[i][4], str))
        self.assertTrue(isinstance(periodic_table._elements[i][5], float)
                        or isinstance(periodic_table._elements[i][5], int))

    def test_that_get_method_works(self):
        expected = ["Ti", 22, 4, 4, "titanium", 47.9000]
        returned = [self.element[i] for i in range(6)]

        self.assertEqual(expected, returned)

    @mock.patch('Muon.GUI.ElementalAnalysis.PeriodicTable.periodic_table._logger.warning')
    def test_that_density_returns_a_warning(self, mock_warning):
        self.assertEqual(self.element[6], 0.0)
        self.assertEqual(mock_warning.call_count, 1)

    def test_that_length_gives_correct_value(self):
        self.assertEqual(self.element.__len__(), 6)
Пример #4
0
 def setUp(self):
     self.ptable = PeriodicTable()
     self.item = PeriodicTableItem("Ti", 22, 4, 4, "titanium", 47.9000,
                                   "transition metal")
Пример #5
0
 def setUp(self):
     self.element = PeriodicTableItem("Ti", 22, 4, 4, "titanium", 47.9000, "transition metal")