Exemple #1
0
    def test_save(self):
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # delete all files
        gister.save(files=None)
        nt.assert_equal(gist.edit.call_count, 1)
        description, files = gist.edit.call_args[0]
        for fn in files:
            nt.assert_is_none(files[fn])

        gist = makeFakeGist()
        gister = Gister(gist, None)
        # add a new file, edit a.ipynb
        gister.save(files={
            'new.txt': 'new.txt content',
            'a.ipynb': 'new content'
        })
        description, files = gist.edit.call_args[0]
        nt.assert_items_equal(files,
                              ['new.txt', 'a.ipynb', 'b.ipynb', 'test.txt'])

        for fn in files:
            f = files[fn]
            if fn == 'new.txt':
                nt.assert_equal(f._InputFileContent__content,
                                'new.txt content')
            elif fn == 'a.ipynb':
                nt.assert_equal(f._InputFileContent__content, 'new content')
            else:
                nt.assert_is_none(f)
Exemple #2
0
    def test_save(self):
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # delete all files
        gister.save(files=None)
        nt.assert_equal(gist.edit.call_count, 1)
        description, files = gist.edit.call_args[0]
        for fn in files:
            nt.assert_is_none(files[fn])

        gist = makeFakeGist()
        gister = Gister(gist, None)
        # add a new file, edit a.ipynb
        gister.save(files={"new.txt": "new.txt content", "a.ipynb": "new content"})
        description, files = gist.edit.call_args[0]
        nt.assert_items_equal(files, ["new.txt", "a.ipynb", "b.ipynb", "test.txt"])

        for fn in files:
            f = files[fn]
            if fn == "new.txt":
                nt.assert_equal(f._InputFileContent__content, "new.txt content")
            elif fn == "a.ipynb":
                nt.assert_equal(f._InputFileContent__content, "new content")
            else:
                nt.assert_is_none(f)
Exemple #3
0
    def test_save(self):
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # delete all files
        gister.save(files=None)
        nt.assert_equal(gist.edit.call_count, 1)
        description, files = gist.edit.call_args[0]
        for fn in files:
            nt.assert_is_none(files[fn])

        gist = makeFakeGist()
        gister = Gister(gist, None)
        # add a new file, edit a.ipynb
        gister.save(files={'new.txt':'new.txt content', 'a.ipynb':'new content'})
        description, files = gist.edit.call_args[0]
        nt.assert_items_equal(files, ['new.txt', 'a.ipynb', 'b.ipynb', 'test.txt'])

        for fn in files:
            f = files[fn]
            if fn == 'new.txt':
                nt.assert_equal(f._InputFileContent__content, 'new.txt content')
            elif fn == 'a.ipynb':
                nt.assert_equal(f._InputFileContent__content, 'new content')
            else:
                nt.assert_is_none(f)
Exemple #4
0
 def test_revisions_for_file(self):
     # TODO not a huge fan of how I mock github.Gist objects
     gist = makeFakeGist()
     tg = TaggedGist.from_gist(gist)
     a_revs = tg.revisions_for_file('a.ipynb')
     # should only have 2 revisions for a.ipynb
     assert len(a_revs) == 2
     # make sure we got the right ones
     for state in a_revs:
         assert 'a.ipynb' in state.raw_data['files']
Exemple #5
0
 def test_revisions_for_file(self):
     # TODO not a huge fan of how I mock github.Gist objects
     gist = makeFakeGist()
     tg = TaggedGist.from_gist(gist)
     a_revs = tg.revisions_for_file('a.ipynb')
     # should only have 2 revisions for a.ipynb
     nt.assert_equal(len(a_revs), 2)
     # make sure we got the right ones
     for state in a_revs:
         nt.assert_in('a.ipynb', state.raw_data['files'])
Exemple #6
0
    def test_is_dirty(self):
        old_desc = "Test Gist #notebook #pandas #woo"
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # change desc
        nt.assert_true(gister._is_dirty("changed desc", files={}))

        # no change
        nt.assert_false(gister._is_dirty(old_desc, files={}))

        # new file
        nt.assert_true(gister._is_dirty(old_desc, files={"new file.txt": "ewn"}))

        # change existing
        nt.assert_true(gister._is_dirty(old_desc, files={"a.ipynb": "ewn"}))

        # same as previous file content
        nt.assert_false(gister._is_dirty(old_desc, files={"a.ipynb": "a.ipynb content"}))
Exemple #7
0
    def test_is_dirty(self):
        old_desc = 'Test Gist #notebook #pandas #woo'
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # change desc
        nt.assert_true(gister._is_dirty('changed desc', files={}))

        # no change
        nt.assert_false(gister._is_dirty(old_desc, files={}))

        # new file
        nt.assert_true(gister._is_dirty(old_desc, files={'new file.txt': 'ewn'}))

        # change existing
        nt.assert_true(gister._is_dirty(old_desc, files={'a.ipynb': 'ewn'}))

        # same as previous file content
        nt.assert_false(gister._is_dirty(old_desc, files={'a.ipynb': 'a.ipynb content'}))
Exemple #8
0
    def test_is_dirty(self):
        old_desc = 'Test Gist #notebook #pandas #woo'
        gist = makeFakeGist()
        gister = Gister(gist, None)

        # change desc
        nt.assert_true(gister._is_dirty('changed desc', files={}))

        # no change
        nt.assert_false(gister._is_dirty(old_desc, files={}))

        # new file
        nt.assert_true(
            gister._is_dirty(old_desc, files={'new file.txt': 'ewn'}))

        # change existing
        nt.assert_true(gister._is_dirty(old_desc, files={'a.ipynb': 'ewn'}))

        # same as previous file content
        nt.assert_false(
            gister._is_dirty(old_desc, files={'a.ipynb': 'a.ipynb content'}))
Exemple #9
0
 def test_get_revision_file(self):
     gist = makeFakeGist()
     tg = TaggedGist.from_gist(gist)
     fo = tg.get_revision_file(0, 'a.ipynb')
     correct = "{fn}_{id}_revision_content".format(fn='a.ipynb', id=0)
     assert fo['content'] == correct
Exemple #10
0
 def test_get_revision_file(self):
     gist = makeFakeGist()
     tg = TaggedGist.from_gist(gist)
     fo = tg.get_revision_file(0, 'a.ipynb')
     correct = "{fn}_{id}_revision_content".format(fn='a.ipynb', id=0)
     nt.assert_equal(fo['content'], correct)