def test_reload(self): """ Check you can initialise a mats object without mats and then add the mats later """ m = mats.Materials() m2 = mats.Materials('mats_test.json') m.reload(m2._materials) self.assertEqual([ "Antimony", "Carbon", "Chromium", "Germanium", "Iron", "Manganese", "Mercury", "Nickel", "Phosphorus", "Sulphur", "Tin", "Tungsten", "Zirconium" ], m.names())
def test_names(self): m = mats.Materials("mats_test.json", NoneVisited()) self.assertEqual([ "Antimony", "Carbon", "Chromium", "Germanium", "Iron", "Manganese", "Mercury", "Nickel", "Phosphorus", "Sulphur", "Tin", "Tungsten", "Zirconium" ], m.names())
def test_local(self): """ Check we can get all the local sites (on the same body) """ m = mats.Materials("mats_test.json", NoneVisited()) self.assertTrue(m.local('164 G. Canis Majoris', '5 c a')) self.assertFalse(m.local('164 G. Canis Majoris', '5 c b'))
def test_closest(self): """ Tests a system is chosen where the mat is present """ m = mats.Materials("mats_test.json", NoneVisited()) self.assertEqual('164 G. Canis Majoris', m.closest([0, 0, 0], ['Tungsten'])[1]['system']) self.assertEqual('2MASS J10433563-5945136', m.closest([0, 0, 0], ['Germanium'])[1]['system'])
def test_matches_all_visited(self): m = mats.Materials("mats_test.json", AllVisited()) self.assertFalse( m.matches({ 'system': '164 G. Canis Majoris', 'body': '5 c a', "lat": -4.8631, "lon": 3.0394 }))
def test_matches_case_insensitive(self): m = mats.Materials("mats_test.json", NoneVisited()) self.assertTrue( m.matches({ 'system': '164 G. canis majoris', 'body': '5 C A', "lat": -4.8631, "lon": 3.0394 }))
def run(self): try: m = mats.Materials(self.filename) self.queue.put({'mats': m._materials}) except: self.queue.put({ 'error': 'Failed to load materials ' + str(sys.exc_info()[0]) })
def test_closest_common_mats(self): """ Test when a mat is present in both systems that the closest is chosen """ m = mats.Materials("mats_test.json", NoneVisited()) self.assertEqual('164 G. Canis Majoris', m.closest([0, 0, 0], ['Iron'])[1]['system']) self.assertEqual('2MASS J10433563-5945136', m.closest([8000, 0, 3000], ['Iron'])[1]['system'])
def test_closest_all_visited(self): """ Check that when all the systems are visited recently we don't return any """ m = mats.Materials("mats_test.json", AllVisited()) self.assertEqual((None, None), m.closest([0, 0, 0], ['Tungsten', 'Germanium'])) self.assertEqual((None, None), m.closest([8000, 0, 3000], ['Tungsten', 'Germanium']))
def plugin_start(): watcher.MatsLoaderRemote(local_file("mats-cache.json"), this.status_queue).start() this.visited = visited.Visited(config.get("matgrindr.visited")) this.mats = mats.Materials(None, this.visited) selected = config.get("matgrindr.selected") or [] this.events = events.EventEngine(this.mats, selected, this.visited) this._IMG_CLIPBOARD = tk.PhotoImage(file=local_file('clipboard-2x.gif')) this._IMG_SKIP = tk.PhotoImage(file=local_file('circle-x-2x.gif')) return "Matgrindr"
def test_closest_multiple_mats(self): """ Check that the closest system with any of the required mats is chosen """ m = mats.Materials("mats_test.json", NoneVisited()) self.assertEqual( '164 G. Canis Majoris', m.closest([0, 0, 0], ['Tungsten', 'Germanium'])[1]['system']) self.assertEqual( '2MASS J10433563-5945136', m.closest([8000, 0, 3000], ['Tungsten', 'Germanium'])[1]['system'])
def test_matches(self): m = mats.Materials("mats_test.json", NoneVisited()) self.assertTrue( m.matches({ 'system': '164 G. Canis Majoris', 'body': '5 c a', "lat": -4.8631, "lon": 3.0394 })) self.assertFalse( m.matches({ 'system': '165 G. Canis Majoris', 'body': '5 c a', "lat": -4.8631, "lon": 3.0394 })) self.assertFalse( m.matches({ 'system': '164 G. Canis Majoris', 'body': '5 c b', "lat": -4.8631, "lon": 3.0394 })) self.assertFalse( m.matches({ 'system': '164 G. Canis Majoris', 'body': '5 c a', "lat": 4.8631, "lon": 3.0394 })) self.assertFalse( m.matches({ 'system': '164 G. Canis Majoris', 'body': '5 c a', "lat": -4.8631, "lon": 7.0394 }))
def test_types(self): m = mats.Materials("mats_test.json", NoneVisited()) self.assertEqual(["Braintree", "Thargoid"], m.types())
def test_names_no_mats(self): """ Check you can initialise a mats object without mats """ m = mats.Materials() self.assertEqual([], m.names())
def test_local_case_insensitive(self): """ Check we can get all the local sites (on the same body) """ m = mats.Materials("mats_test.json", NoneVisited()) self.assertTrue(m.local('164 G. canis majoris', '5 C A'))