import os
import tempfile
import shutil
import tzlocal
import pytest
from ..mongoquery.mds import MDS


@pytest.fixture(params=[1], scope='function')
def mds_all(request):
    '''Provide a function level scoped FileStore instance talking to
    temporary database on localhost:27017 with both v0 and v1.

    '''
    ver = request.param
    tempdirname = tempfile.mkdtemp()
    mds = MDS({'directory': tempdirname,
               'timezone': tzlocal.get_localzone().zone}, version=ver)
    filenames = ['run_starts.json', 'run_stops.json', 'event_descriptors.json',
                 'events.json']
    for fn in filenames:
        with open(os.path.join(tempdirname, fn), 'w') as f:
            f.write('[]')

    def delete_dm():
        shutil.rmtree(tempdirname)

    request.addfinalizer(delete_dm)

    return mds

import os
import tempfile
import shutil
import tzlocal
import pytest
import portable_mds.mongoquery.mds
import portable_mds.sqlite.mds

variations = [portable_mds.mongoquery.mds,
              portable_mds.sqlite.mds]

@pytest.fixture(params=variations, scope='function')
def mds_all(request):
    '''Provide a function level scoped FileStore instance talking to
    temporary database on localhost:27017 with both v0 and v1.

    '''
    tempdirname = tempfile.mkdtemp()
    mds = request.param.MDS({'directory': tempdirname,
               'timezone': tzlocal.get_localzone().zone}, version=1)
    filenames = ['run_starts.json', 'run_stops.json', 'event_descriptors.json',
                 'events.json']
    for fn in filenames:
        with open(os.path.join(tempdirname, fn), 'w') as f:
            f.write('[]')

    def delete_dm():
        shutil.rmtree(tempdirname)

    request.addfinalizer(delete_dm)

    return mds

Test sqlite and mongoquery variations.
TST: Test sqlite and mongoquery variations.

  import os
  import tempfile
  import shutil
  import tzlocal
  import pytest
- from ..mongoquery.mds import MDS
+ import portable_mds.mongoquery.mds
+ import portable_mds.sqlite.mds
  
+ variations = [portable_mds.mongoquery.mds,
+               portable_mds.sqlite.mds]
  
- @pytest.fixture(params=[1], scope='function')
+ @pytest.fixture(params=variations, scope='function')
  def mds_all(request):
      '''Provide a function level scoped FileStore instance talking to
      temporary database on localhost:27017 with both v0 and v1.
  
      '''
-     ver = request.param
      tempdirname = tempfile.mkdtemp()
-     mds = MDS({'directory': tempdirname,
+     mds = request.param.MDS({'directory': tempdirname,
-                'timezone': tzlocal.get_localzone().zone}, version=ver)
+                'timezone': tzlocal.get_localzone().zone}, version=1)
      filenames = ['run_starts.json', 'run_stops.json', 'event_descriptors.json',
                   'events.json']
      for fn in filenames:
          with open(os.path.join(tempdirname, fn), 'w') as f:
              f.write('[]')
  
      def delete_dm():
          shutil.rmtree(tempdirname)
  
      request.addfinalizer(delete_dm)
  
      return mds
  
Test sqlite and mongoquery variations.
## Code Before:
import os
import tempfile
import shutil
import tzlocal
import pytest
from ..mongoquery.mds import MDS


@pytest.fixture(params=[1], scope='function')
def mds_all(request):
    '''Provide a function level scoped FileStore instance talking to
    temporary database on localhost:27017 with both v0 and v1.

    '''
    ver = request.param
    tempdirname = tempfile.mkdtemp()
    mds = MDS({'directory': tempdirname,
               'timezone': tzlocal.get_localzone().zone}, version=ver)
    filenames = ['run_starts.json', 'run_stops.json', 'event_descriptors.json',
                 'events.json']
    for fn in filenames:
        with open(os.path.join(tempdirname, fn), 'w') as f:
            f.write('[]')

    def delete_dm():
        shutil.rmtree(tempdirname)

    request.addfinalizer(delete_dm)

    return mds

## Instruction:
Test sqlite and mongoquery variations.
## Code After:
import os
import tempfile
import shutil
import tzlocal
import pytest
import portable_mds.mongoquery.mds
import portable_mds.sqlite.mds

variations = [portable_mds.mongoquery.mds,
              portable_mds.sqlite.mds]

@pytest.fixture(params=variations, scope='function')
def mds_all(request):
    '''Provide a function level scoped FileStore instance talking to
    temporary database on localhost:27017 with both v0 and v1.

    '''
    tempdirname = tempfile.mkdtemp()
    mds = request.param.MDS({'directory': tempdirname,
               'timezone': tzlocal.get_localzone().zone}, version=1)
    filenames = ['run_starts.json', 'run_stops.json', 'event_descriptors.json',
                 'events.json']
    for fn in filenames:
        with open(os.path.join(tempdirname, fn), 'w') as f:
            f.write('[]')

    def delete_dm():
        shutil.rmtree(tempdirname)

    request.addfinalizer(delete_dm)

    return mds
