diff --git a/test/addSelect.vader b/test/addSelect.vader new file mode 100644 index 0000000000000000000000000000000000000000..4a2e9e4643dde60b7b7ed8f06c202f928dc003d9 --- /dev/null +++ b/test/addSelect.vader @@ -0,0 +1,59 @@ +Include: setup.inc + +Execute (Stage untracked file with magit#stage_hunk on start hunk (this hunk will stay staged all test)): + call Cd_test_sub() + Magit + call Search_file('unstaged') + call magit#open_close_folding(1) + call Search_pattern("^@@ ") + call Cursor_position() + call magit#stage_hunk(0) + call Cd_test() + let diff=Git_diff('staged', Get_filename()) + call Expect_diff(g:test_script_dir . 'addSelect/addSelect_' . Get_safe_filename() . '_1_hunk_diff.expect', diff) + +Execute (Stage selection): + call Cd_test_sub() + Magit + call Search_file('unstaged') + call magit#open_close_folding(1) + %foldopen! + call Search_pattern("^+\t\tif product.cover_url is not '':$") + execute "normal! v4j:call magit#stage_vselect()\<cr>" + call Cd_test() + let diff=Git_diff('staged', Get_filename()) + call Expect_diff(g:test_script_dir . 'addSelect/addSelect_' . Get_safe_filename() . '_2_vselect_diff.expect', diff) + +Execute (Stage lines): + call Cd_test_sub() + Magit + call Search_file('unstaged') + call magit#open_close_folding(1) + %foldopen! + call Search_pattern("^-\teisbn = models.CharField(max_length=13, blank=True)$") + call magit#stage_vselect() + %foldopen! + call Search_pattern("^+\teisbn = models.CharField(max_length=13, blank=True, null=True)$") + call magit#stage_vselect() + call Cd_test() + let diff=Git_diff('staged', Get_filename()) + call Expect_diff(g:test_script_dir . 'addSelect/addSelect_' . Get_safe_filename() . '_3_lines_diff.expect', diff) + +Execute (Stage marks): + call Cd_test_sub() + Magit + call Search_file('unstaged') + call magit#open_close_folding(1) + %foldopen! + call Search_pattern("^+def upload_path(book, filename):$") + execute "normal! v3j:call magit#mark_vselect()\<cr>" + call Search_pattern("^-\tedition = models.CharField(max_length=200, blank=True)$") + call magit#mark_vselect() + call Search_pattern("+\tedition = models.CharField(max_length=200, blank=True, null=True)$") + call magit#mark_vselect() + call magit#stage_hunk(0) + call Cd_test() + let diff=Git_diff('staged', Get_filename()) + call Expect_diff(g:test_script_dir . 'addSelect/addSelect_' . Get_safe_filename() . '_4_marks_diff.expect', diff) + +Include: cleanup.inc diff --git a/test/addSelect/addSelect_books_models_py_1_hunk_diff.expect b/test/addSelect/addSelect_books_models_py_1_hunk_diff.expect new file mode 100644 index 0000000000000000000000000000000000000000..4d9138a938c57a7b32e49aa6e00289063c97ab00 --- /dev/null +++ b/test/addSelect/addSelect_books_models_py_1_hunk_diff.expect @@ -0,0 +1,13 @@ +diff --git books/models.py books/models.py +--- books/models.py ++++ books/models.py +@@ -1,5 +1,9 @@ + from django.db import models + ++import urllib2 as urllib ++from PIL import Image ++import io ++ + import isbn_search + + class User(models.Model): diff --git a/test/addSelect/addSelect_books_models_py_2_vselect_diff.expect b/test/addSelect/addSelect_books_models_py_2_vselect_diff.expect new file mode 100644 index 0000000000000000000000000000000000000000..313e368f29470f6ff6a979618df9315f464b9697 --- /dev/null +++ b/test/addSelect/addSelect_books_models_py_2_vselect_diff.expect @@ -0,0 +1,24 @@ +diff --git books/models.py books/models.py +--- books/models.py ++++ books/models.py +@@ -1,5 +1,9 @@ + from django.db import models + ++import urllib2 as urllib ++from PIL import Image ++import io ++ + import isbn_search + + class User(models.Model): +@@ -22,6 +26,10 @@ class BookManager(models.Manager): + title = product.title, + edition = product.edition + ) ++ if product.cover_url is not '': ++ cover_img_bin = urllib.urlopen(product.cover_url) ++ cover_img_file = Image.open(io.BytesIO(cover_img_bin.read())) ++ book.cover_img.save("cover.jpg", cover_img_file) + return book + + class Book(models.Model): diff --git a/test/addSelect/addSelect_books_models_py_3_lines_diff.expect b/test/addSelect/addSelect_books_models_py_3_lines_diff.expect new file mode 100644 index 0000000000000000000000000000000000000000..0698fb66d39dc915ee85ca4076aed3be3897f47b --- /dev/null +++ b/test/addSelect/addSelect_books_models_py_3_lines_diff.expect @@ -0,0 +1,30 @@ +diff --git books/models.py books/models.py +--- books/models.py ++++ books/models.py +@@ -1,5 +1,9 @@ + from django.db import models + ++import urllib2 as urllib ++from PIL import Image ++import io ++ + import isbn_search + + class User(models.Model): +@@ -22,11 +26,15 @@ class BookManager(models.Manager): + title = product.title, + edition = product.edition + ) ++ if product.cover_url is not '': ++ cover_img_bin = urllib.urlopen(product.cover_url) ++ cover_img_file = Image.open(io.BytesIO(cover_img_bin.read())) ++ book.cover_img.save("cover.jpg", cover_img_file) + return book + + class Book(models.Model): + isbn = models.CharField(max_length=10, unique=True) +- eisbn = models.CharField(max_length=13, blank=True) ++ eisbn = models.CharField(max_length=13, blank=True, null=True) + title = models.CharField(max_length=200) + author = models.CharField(max_length=200) + edition = models.CharField(max_length=200, blank=True) diff --git a/test/addSelect/addSelect_books_models_py_4_marks_diff.expect b/test/addSelect/addSelect_books_models_py_4_marks_diff.expect new file mode 100644 index 0000000000000000000000000000000000000000..e4dfb93e28e550be0d1e434cd6792eb11b0224ab --- /dev/null +++ b/test/addSelect/addSelect_books_models_py_4_marks_diff.expect @@ -0,0 +1,38 @@ +diff --git books/models.py books/models.py +--- books/models.py ++++ books/models.py +@@ -1,5 +1,9 @@ + from django.db import models + ++import urllib2 as urllib ++from PIL import Image ++import io ++ + import isbn_search + + class User(models.Model): +@@ -22,15 +26,22 @@ class BookManager(models.Manager): + title = product.title, + edition = product.edition + ) ++ if product.cover_url is not '': ++ cover_img_bin = urllib.urlopen(product.cover_url) ++ cover_img_file = Image.open(io.BytesIO(cover_img_bin.read())) ++ book.cover_img.save("cover.jpg", cover_img_file) + return book + ++def upload_path(book, filename): ++ return 'covers/%s/%s' % (book.isbn, filename) ++ + class Book(models.Model): + isbn = models.CharField(max_length=10, unique=True) +- eisbn = models.CharField(max_length=13, blank=True) ++ eisbn = models.CharField(max_length=13, blank=True, null=True) + title = models.CharField(max_length=200) + author = models.CharField(max_length=200) +- edition = models.CharField(max_length=200, blank=True) + cover = models.ImageField(upload_to='covers', blank=True) ++ edition = models.CharField(max_length=200, blank=True, null=True) + def __unicode__(self): + return u'[%s] "%s" by %s' % (self.isbn, self.title, self.author,) + diff --git a/test/test.config b/test/test.config index 4178717e86c3c1e59b320ede44f9f6f1aa0d550d..f99a8de32f6a1456cd85cf635928151bba72e028 100644 --- a/test/test.config +++ b/test/test.config @@ -2,6 +2,7 @@ declare -a test_paths=(./ ./books/templates/) declare -A test_scripts=( [addFile.vader]='bootstrap;books/models.py;bootstrap.lnk;empty_file;bootstrap\ with\ spaces;bootstrap\ with\ spaces.lnk;empty_file\ with\ spaces' [addHunk.vader]='bootstrap;books/models.py' + [addSelect.vader]='books/models.py' [renameFile.vader]='manage.py|manage\ with\ spaces.py;djooks/settings\ with\ spaces.py|djooks/settings_without_spaces.py' [ignoreFile.vader]='bootstrap' ) diff --git a/test/utils.vim b/test/utils.vim index 975b4faf9e0f8bb0a97875eb7aaa827d6169e1f1..4410147282b38803d41971f46db5ae03680ef210 100644 --- a/test/utils.vim +++ b/test/utils.vim @@ -150,10 +150,15 @@ function! Search_file(mode, ...) call Git_verbose_log('Search mode: "' . a:mode . '" => ' . getline('.')) let pattern='^.*: ' . call('Get_filename', a:000) . '\%( -> .*\)\?$' let ret = search(pattern) - call Git_verbose_log('Search: "' . pattern . '" => ' . getline('.')) + call Git_verbose_log('Search: "' . pattern . '" => ' . getline('.') . ' @line' . line('.')) return ret endfunction +function! Search_pattern(pattern) + let ret = search(a:pattern) + call Git_verbose_log('Search: "' . a:pattern . '" => ' . getline('.') . ' @line' . line('.')) +endfunction + " get a safe to use string of filename we curently test (for golden files) function! Get_safe_filename(...) return substitute(call('Get_filename', a:000), '[/. ]', '_', 'g')