-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update objects when path changes for MultiFileSelector and FileSelector #546
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fe6b19e
switch to repr in the validation error message
maximlt fb83c58
fix old and new
maximlt bde1048
FileSelector: update objects when path is updated and default to None
maximlt f9443e9
MultiFileSelecto: update objects when path change and default to None
maximlt 11231db
Add tests
maximlt 4b2f774
Define path as a kwarg whose default is None
maximlt 4279bfe
Add tests
maximlt 08b7331
remove _on_set and reset initial default behaviour
maximlt 75dfc79
Update docs
maximlt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import param | ||
|
||
from . import API1TestCase | ||
|
||
|
||
class TestFileSelectorParameters(API1TestCase): | ||
|
||
def setUp(self): | ||
super(TestFileSelectorParameters, self).setUp() | ||
|
||
tmpdir1 = tempfile.mkdtemp() | ||
fa = os.path.join(tmpdir1, 'a.txt') | ||
fb = os.path.join(tmpdir1, 'b.txt') | ||
glob1 = os.path.join(tmpdir1, '*') | ||
open(fa, 'w').close() | ||
open(fb, 'w').close() | ||
tmpdir2 = tempfile.mkdtemp() | ||
fc = os.path.join(tmpdir2, 'c.txt') | ||
fd = os.path.join(tmpdir2, 'd.txt') | ||
glob2 = os.path.join(tmpdir2, '*') | ||
open(fc, 'w').close() | ||
open(fd, 'w').close() | ||
|
||
self.tmpdir1 = tmpdir1 | ||
self.tmpdir2 = tmpdir2 | ||
self.fa = fa | ||
self.fb = fb | ||
self.fc = fc | ||
self.fd = fd | ||
self.glob1 = glob1 | ||
self.glob2 = glob2 | ||
|
||
class P(param.Parameterized): | ||
a = param.FileSelector(path=glob1) | ||
b = param.FileSelector(default=fa, path=glob1) | ||
|
||
self.P = P | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.tmpdir1) | ||
shutil.rmtree(self.tmpdir2) | ||
|
||
def test_default_is_None(self): | ||
p = self.P() | ||
assert p.a is None | ||
assert p.param.a.default is None | ||
|
||
def test_default_is_honored(self): | ||
p = self.P() | ||
assert p.b == self.fa | ||
assert p.param.b.default in [self.fa, self.fb] | ||
|
||
def test_allow_default_None(self): | ||
class P(param.Parameterized): | ||
a = param.FileSelector(default=None) | ||
|
||
def test_default_not_in_glob(self): | ||
with self.assertRaises(ValueError): | ||
class P(param.Parameterized): | ||
a = param.FileSelector(default='not/in/glob', path=self.glob1) | ||
|
||
def test_objects_auto_set(self): | ||
p = self.P() | ||
assert p.param.a.objects == [self.fa, self.fb] | ||
|
||
def test_set_object_constructor(self): | ||
p = self.P(a=self.fb) | ||
assert p.a == self.fb | ||
|
||
def test_set_object_outside_bounds(self): | ||
p = self.P() | ||
with self.assertRaises(ValueError): | ||
p.a = '/not/in/glob' | ||
|
||
def test_set_path_and_update(self): | ||
p = self.P() | ||
p.param.b.path = self.glob2 | ||
p.param.b.update() | ||
assert p.param.b.objects == [self.fc, self.fd] | ||
assert p.param.b.default in [self.fc, self.fd] | ||
# Default updated but not the value itself | ||
assert p.b == self.fa | ||
|
||
def test_get_range(self): | ||
p = self.P() | ||
r = p.param.a.get_range() | ||
assert r['a.txt'] == self.fa | ||
assert r['b.txt'] == self.fb | ||
p.param.a.path = self.glob2 | ||
p.param.a.update() | ||
r = p.param.a.get_range() | ||
assert r['c.txt'] == self.fc | ||
assert r['d.txt'] == self.fd | ||
|
||
def test_update_file_removed(self): | ||
p = self.P() | ||
assert p.param.b.objects == [self.fa, self.fb] | ||
assert p.param.b.default in [self.fa, self.fb] | ||
os.remove(self.fa) | ||
p.param.b.update() | ||
assert p.param.b.objects == [self.fb] | ||
assert p.param.b.default == self.fb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import param | ||
|
||
from . import API1TestCase | ||
|
||
|
||
class TestMultiFileSelectorParameters(API1TestCase): | ||
|
||
def setUp(self): | ||
super(TestMultiFileSelectorParameters, self).setUp() | ||
|
||
tmpdir1 = tempfile.mkdtemp() | ||
fa = os.path.join(tmpdir1, 'a.txt') | ||
fb = os.path.join(tmpdir1, 'b.txt') | ||
glob1 = os.path.join(tmpdir1, '*') | ||
open(fa, 'w').close() | ||
open(fb, 'w').close() | ||
tmpdir2 = tempfile.mkdtemp() | ||
fc = os.path.join(tmpdir2, 'c.txt') | ||
fd = os.path.join(tmpdir2, 'd.txt') | ||
glob2 = os.path.join(tmpdir2, '*') | ||
open(fc, 'w').close() | ||
open(fd, 'w').close() | ||
|
||
self.tmpdir1 = tmpdir1 | ||
self.tmpdir2 = tmpdir2 | ||
self.fa = fa | ||
self.fb = fb | ||
self.fc = fc | ||
self.fd = fd | ||
self.glob1 = glob1 | ||
self.glob2 = glob2 | ||
|
||
class P(param.Parameterized): | ||
a = param.MultiFileSelector(path=glob1) | ||
b = param.MultiFileSelector(default=[fa], path=glob1) | ||
|
||
self.P = P | ||
|
||
def tearDown(self): | ||
shutil.rmtree(self.tmpdir1) | ||
shutil.rmtree(self.tmpdir2) | ||
|
||
def test_default_is_None(self): | ||
p = self.P() | ||
assert p.a is None | ||
assert p.param.a.default is None | ||
|
||
def test_default_is_honored(self): | ||
p = self.P() | ||
assert p.b == [self.fa] | ||
assert p.param.b.default ==[self.fa] | ||
|
||
def test_allow_default_None(self): | ||
class P(param.Parameterized): | ||
a = param.FileSelector(default=None) | ||
|
||
def test_objects_auto_set(self): | ||
p = self.P() | ||
assert p.param.a.objects == [self.fa, self.fb] | ||
|
||
def test_default_not_in_glob(self): | ||
with self.assertRaises(ValueError): | ||
class P(param.Parameterized): | ||
a = param.FileSelector(default=['not/in/glob'], path=self.glob1) | ||
|
||
def test_objects_auto_set(self): | ||
p = self.P() | ||
assert sorted(p.param.a.objects) == sorted([self.fa, self.fb]) | ||
|
||
def test_set_object_constructor(self): | ||
p = self.P(a=[self.fb]) | ||
assert p.a == [self.fb] | ||
|
||
def test_set_object_outside_bounds(self): | ||
p = self.P() | ||
with self.assertRaises(ValueError): | ||
p.a = ['/not/in/glob'] | ||
|
||
def test_set_path_and_update(self): | ||
p = self.P() | ||
p.param.b.path = self.glob2 | ||
p.param.b.update() | ||
assert sorted(p.param.b.objects) == sorted([self.fc, self.fd]) | ||
assert sorted(p.param.b.default) == sorted([self.fc, self.fd]) | ||
# Default updated but not the value itself | ||
assert p.b == [self.fa] | ||
|
||
def test_get_range(self): | ||
p = self.P() | ||
r = p.param.a.get_range() | ||
assert r['a.txt'] == self.fa | ||
assert r['b.txt'] == self.fb | ||
p.param.a.path = self.glob2 | ||
p.param.a.update() | ||
r = p.param.a.get_range() | ||
assert r['c.txt'] == self.fc | ||
assert r['d.txt'] == self.fd | ||
|
||
def test_update_file_removed(self): | ||
p = self.P() | ||
assert p.param.b.objects == [self.fa, self.fb] | ||
assert p.param.b.default == [self.fa] | ||
os.remove(self.fa) | ||
p.param.b.update() | ||
assert p.param.b.objects == [self.fb] | ||
assert p.param.b.default == [self.fb] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to say two different values for the default, which presumably can't be true?