Esempio n. 1
0
 def test_plugin_option(self, mdefs):
     emf = emf_random.EMFetcher_random(mdefs[1])
     assert emf.plugin_option('foo') == 123
     assert emf.plugin_option('bar.zig') == "Zoom"
     with pytest.raises(KeyError):
         emf.plugin_option('BOGUS')
     assert emf.plugin_option('BOGUS', default="D") == "D"
Esempio n. 2
0
 def test_bad_timerange(self, mdefs):
     emf = emf_random.EMFetcher_random(mdefs[1])
     with pytest.raises(TypeError):
         emf.fetch('Not TimeRange')
     tmrange3 = timerange.TimeRange()
     with pytest.raises(ValueError):
         emf.fetch(tmrange3)
Esempio n. 3
0
 def test_format_param_extinfo(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     emf.fetch(tmranges[2])  # (causes plugin to set its self._tmrange)
     assert emf._format_str('{extinfo[a]}') == "65"
     assert emf._format_str('{extinfo[special][q]}') == "34"
     with pytest.raises(KeyError):
         emf._format_str('{extinfo[special][BOGUS]}')
Esempio n. 4
0
 def test_plugin_extinfo(self, mdefs):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     assert emf.plugin_extinfo('a') == 65
     assert emf.plugin_extinfo('b') == "LilB"
     with pytest.raises(KeyError):
         emf.plugin_extinfo('BOGUS')
     assert emf.plugin_extinfo('BOGUS', default="D") == "D"
Esempio n. 5
0
 def test_random(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1])
     emf.plugin_create()
     for x in range(100):
         dpoint1 = emf.fetch(tmranges[1])
         assert (0 <= dpoint1.value <= 100)
     emf.configure(options={'random': {'round': True}})
     assert isinstance(emf.fetch(tmranges[1]).value, (int, long))
     emf.plugin_destroy()
Esempio n. 6
0
 def test_format_param_bad(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     emf.fetch(tmranges[2])  # (causes plugin to set its self._tmrange)
     with pytest.raises(TypeError):
         emf._format_str(12345)
     with pytest.raises(TypeError):
         emf._format_str(None)
     with pytest.raises(KeyError):
         emf._format_str('{BOGUS}')
Esempio n. 7
0
 def test_format_param_str(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     emf.fetch(tmranges[2])  # (causes plugin to set its self._tmrange)
     assert emf._format_str("plain") == "plain"
     assert emf._format_str("My {mdef.table} here") == "My tblname here"
     assert emf._format_str("{tmrange.inc_begin:%Y-%m-%d}") == "2014-04-14"
     assert emf._format_str(
         "{tmrange.exc_end:%Y-%m-%d %H:%M:%S}") == "2014-04-15 16:42:45"
     assert emf._format_str("{tmrange.exc_end:%s}") == "1397605365"
Esempio n. 8
0
 def test_format_params(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     emf.fetch(tmranges[2])  # (causes plugin to set its self._tmrange)
     params_spec = {
         'plain': "plainval",
         'mdef': "My {mdef.table} here",
         'lit': "{{mdef.table}}",
         'ext': '{extinfo[special][q]}',
     }
     params = dict()
     for k, v in params_spec.iteritems():
         params[k] = emf._format_str(v)
     assert params['plain'] == "plainval"
     assert params['mdef'] == "My tblname here"
     assert params['lit'] == "{mdef.table}"
     assert params['ext'] == "34"
Esempio n. 9
0
 def test_bad_metricdef(self, mdefs):
     with pytest.raises(TypeError):
         emf_random.EMFetcher_random('Not MetricDef')
     mdefs[1].emfetch_id = ''
     with pytest.raises(ValueError):
         emf_random.EMFetcher_random(mdefs[1])
Esempio n. 10
0
 def test_format_param_literal(self, mdefs, tmranges):
     emf = emf_random.EMFetcher_random(mdefs[1], extinfo=self.extinfo)
     emf.fetch(tmranges[2])  # (causes plugin to set its self._tmrange)
     assert emf._format_str('plain') == "plain"
     assert emf._format_str(
         "My {{mdef.table}} here") == "My {mdef.table} here"