Exemplo n.º 1
0
class ContextTests(DependencyInjectionTestBase):
    def setUp(self):
        super(ContextTests, self).setUp()
        patcher = patch('niprov.context.niprov')
        self.niprov = patcher.start()
        self.addCleanup(patcher.stop)
        from niprov import ProvenanceContext
        self.context = ProvenanceContext()
        self.context.deps = self.dependencies

    def test_get(self):
        self.assertEqual(self.context.get(), self.query)

    def test_add(self):
        self.context.add('file.p', True, {'c': 3})
        self.niprov.adding.add.assert_called_with('file.p', True, {'c': 3},
                                                  self.dependencies)

    def test_log(self):
        self.context.log('new', 'trf', 'parents', 'code', 'logtext', False,
                         'script', 'user', {'prov': 1}, 'opts')
        self.niprov.plogging.log.assert_called_with('new', 'trf', 'parents',
                                                    'code', 'logtext', False,
                                                    'script', 'user',
                                                    {'prov': 1}, 'opts',
                                                    self.dependencies)

    def test_backup(self):
        self.context.backup()
        self.niprov.exporting.backup.assert_called_with(self.dependencies)

    def test_export(self):
        self.context.export('prov', 'medium', 'form')
        self.niprov.exporting.export.assert_called_with(
            'prov', 'medium', 'form', False, self.dependencies)

    def test_import(self):
        self.context.importp('fpath')
        self.niprov.importing.importp.assert_called_with(
            'fpath', self.dependencies)

    def test_print(self):
        self.context.print_('images')
        self.niprov.exporting.print_.assert_called_with(
            'images', False, self.dependencies)

    def test_record(self):
        self.context.record('cmd', 'new', 'parents', True, 'args', 'kwargs',
                            'user', 'opts')
        self.niprov.recording.record.assert_called_with(
            'cmd', 'new', 'parents', True, 'args', 'kwargs', 'user', 'opts',
            self.dependencies)

    def test_view(self):
        self.context.view('images', pipeline=True)
        self.niprov.exporting.view.assert_called_with('images', True,
                                                      self.dependencies)
Exemplo n.º 2
0
class ContextTests(DependencyInjectionTestBase):

    def setUp(self):
        super(ContextTests, self).setUp()
        patcher = patch('niprov.context.niprov')
        self.niprov = patcher.start()
        self.addCleanup(patcher.stop)
        from niprov import ProvenanceContext
        self.context = ProvenanceContext()
        self.context.deps = self.dependencies

    def test_get(self):
        self.assertEqual(self.context.get(), self.query)

    def test_add(self):
        self.context.add('file.p', True, {'c':3})
        self.niprov.adding.add.assert_called_with('file.p', True, {'c':3},
            self.dependencies)

    def test_log(self):
        self.context.log('new', 'trf', 'parents', 'code', 'logtext', False,
            'script', 'user', {'prov':1}, 'opts')
        self.niprov.plogging.log.assert_called_with('new', 'trf', 'parents', 
            'code', 'logtext', False, 'script', 'user', {'prov':1}, 'opts',
            self.dependencies)

    def test_backup(self):
        self.context.backup()
        self.niprov.exporting.backup.assert_called_with(self.dependencies)

    def test_export(self):
        self.context.export('prov', 'medium', 'form')
        self.niprov.exporting.export.assert_called_with('prov', 'medium',
            'form', False, self.dependencies)

    def test_import(self):
        self.context.importp('fpath')
        self.niprov.importing.importp.assert_called_with('fpath',
            self.dependencies)

    def test_print(self):
        self.context.print_('images')
        self.niprov.exporting.print_.assert_called_with('images', False, 
            self.dependencies)

    def test_record(self):
        self.context.record('cmd', 'new', 'parents', True, 'args', 'kwargs', 
            'user', 'opts')
        self.niprov.recording.record.assert_called_with('cmd', 'new', 
            'parents', True, 'args', 'kwargs', 'user', 'opts',
            self.dependencies)

    def test_view(self):
        self.context.view('images', pipeline=True)
        self.niprov.exporting.view.assert_called_with('images', True, 
            self.dependencies)
Exemplo n.º 3
0
class TerminalApiTests(unittest.TestCase):
    def setUp(self):
        self.dbpath = os.path.expanduser(
            os.path.join('~', 'provenance_test.json'))
        if os.path.exists(self.dbpath):
            os.remove(self.dbpath)
        os.mkdir('temp')
        from niprov import ProvenanceContext
        self.provenance = ProvenanceContext()
        self.provenance.config.database_type = 'file'
        self.provenance.config.database_url = self.dbpath
        self.provenance.config.verbose = False
        self.oldstdout = sys.stdout
        sys.stdout = self.stdout = StringIO()

    def tearDown(self):
        sys.stdout = self.oldstdout
        self.stdout.close()
        shutil.rmtree('temp')

    @unittest.skip("Doesn't work on travis")
    def test_Report_pipeline(self):
        self.provenance.discover('testdata')
        raw = os.path.abspath('testdata/eeg/stub.cnt')
        self.provenance.log(absp('p1a.f'), 'test', raw, transient=True)
        self.provenance.log(absp('p1b.f'), 'test', raw, transient=True)
        self.provenance.log(absp('p2.f'),
                            'test',
                            absp('p1a.f'),
                            transient=True)
        self.provenance.export(None, 'stdout', 'simple', pipeline=True)
        exp = ''
        exp += '+---stub.cnt\n'
        exp += '|   +---p1a.f\n'
        exp += '|   |   +---p2.f\n'
        #exp += '|   +---p1b.f\n' # p1b is not related to p2f
        import time
        time.sleep(0.3)
        self.assertIn(exp, self.stdout.getvalue())
Exemplo n.º 4
0
class TerminalApiTests(unittest.TestCase):

    def setUp(self):
        self.dbpath = os.path.expanduser(os.path.join('~','provenance_test.json'))
        if os.path.exists(self.dbpath):
            os.remove(self.dbpath)
        os.mkdir('temp')
        from niprov import ProvenanceContext
        self.provenance = ProvenanceContext()
        self.provenance.config.database_type = 'file'
        self.provenance.config.database_url = self.dbpath
        self.provenance.config.verbose = False
        self.oldstdout = sys.stdout
        sys.stdout = self.stdout = StringIO()

    def tearDown(self):
        sys.stdout = self.oldstdout
        self.stdout.close()
        shutil.rmtree('temp')

    @unittest.skip("Doesn't work on travis")
    def test_Report_pipeline(self):
        self.provenance.discover('testdata')
        raw = os.path.abspath('testdata/eeg/stub.cnt')
        self.provenance.log(absp('p1a.f'), 'test', raw, transient=True)
        self.provenance.log(absp('p1b.f'), 'test', raw, transient=True)
        self.provenance.log(absp('p2.f'), 'test', absp('p1a.f'), transient=True)
        self.provenance.export(None, 'stdout', 'simple', pipeline=True)
        exp = ''
        exp += '+---stub.cnt\n'
        exp += '|   +---p1a.f\n'
        exp += '|   |   +---p2.f\n'
        #exp += '|   +---p1b.f\n' # p1b is not related to p2f
        import time
        time.sleep(0.3)
        self.assertIn(exp, self.stdout.getvalue())