|
15 | 15 | IncompatibilityWarning, PerformanceWarning,
|
16 | 16 | AttributeConflictWarning, DuplicateWarning,
|
17 | 17 | PossibleDataLossError, ClosedFileError)
|
| 18 | +from pandas.io import pytables as pytables |
18 | 19 | import pandas.util.testing as tm
|
19 | 20 | from pandas.util.testing import (assert_panel4d_equal,
|
20 | 21 | assert_panel_equal,
|
@@ -3683,53 +3684,66 @@ def test_multiple_open_close(self):
|
3683 | 3684 | self.assert_('CLOSED' in str(store))
|
3684 | 3685 | self.assert_(not store.is_open)
|
3685 | 3686 |
|
3686 |
| - # multiples |
3687 |
| - store1 = HDFStore(path) |
3688 |
| - store2 = HDFStore(path) |
3689 |
| - |
3690 |
| - self.assert_('CLOSED' not in str(store1)) |
3691 |
| - self.assert_('CLOSED' not in str(store2)) |
3692 |
| - self.assert_(store1.is_open) |
3693 |
| - self.assert_(store2.is_open) |
3694 |
| - |
3695 |
| - store1.close() |
3696 |
| - self.assert_('CLOSED' in str(store1)) |
3697 |
| - self.assert_(not store1.is_open) |
3698 |
| - self.assert_('CLOSED' not in str(store2)) |
3699 |
| - self.assert_(store2.is_open) |
3700 |
| - |
3701 |
| - store2.close() |
3702 |
| - self.assert_('CLOSED' in str(store1)) |
3703 |
| - self.assert_('CLOSED' in str(store2)) |
3704 |
| - self.assert_(not store1.is_open) |
3705 |
| - self.assert_(not store2.is_open) |
3706 |
| - |
3707 |
| - # nested close |
3708 |
| - store = HDFStore(path,mode='w') |
3709 |
| - store.append('df',df) |
| 3687 | + with ensure_clean_path(self.path) as path: |
3710 | 3688 |
|
3711 |
| - store2 = HDFStore(path) |
3712 |
| - store2.append('df2',df) |
3713 |
| - store2.close() |
3714 |
| - self.assert_('CLOSED' in str(store2)) |
3715 |
| - self.assert_(not store2.is_open) |
| 3689 | + if pytables._table_file_open_policy_is_strict: |
3716 | 3690 |
|
3717 |
| - store.close() |
3718 |
| - self.assert_('CLOSED' in str(store)) |
3719 |
| - self.assert_(not store.is_open) |
| 3691 | + # multiples |
| 3692 | + store1 = HDFStore(path) |
| 3693 | + def f(): |
| 3694 | + HDFStore(path) |
| 3695 | + self.assertRaises(ValueError, f) |
| 3696 | + store1.close() |
3720 | 3697 |
|
3721 |
| - # double closing |
3722 |
| - store = HDFStore(path,mode='w') |
3723 |
| - store.append('df', df) |
| 3698 | + else: |
3724 | 3699 |
|
3725 |
| - store2 = HDFStore(path) |
3726 |
| - store.close() |
3727 |
| - self.assert_('CLOSED' in str(store)) |
3728 |
| - self.assert_(not store.is_open) |
| 3700 | + # multiples |
| 3701 | + store1 = HDFStore(path) |
| 3702 | + store2 = HDFStore(path) |
| 3703 | + |
| 3704 | + self.assert_('CLOSED' not in str(store1)) |
| 3705 | + self.assert_('CLOSED' not in str(store2)) |
| 3706 | + self.assert_(store1.is_open) |
| 3707 | + self.assert_(store2.is_open) |
| 3708 | + |
| 3709 | + store1.close() |
| 3710 | + self.assert_('CLOSED' in str(store1)) |
| 3711 | + self.assert_(not store1.is_open) |
| 3712 | + self.assert_('CLOSED' not in str(store2)) |
| 3713 | + self.assert_(store2.is_open) |
| 3714 | + |
| 3715 | + store2.close() |
| 3716 | + self.assert_('CLOSED' in str(store1)) |
| 3717 | + self.assert_('CLOSED' in str(store2)) |
| 3718 | + self.assert_(not store1.is_open) |
| 3719 | + self.assert_(not store2.is_open) |
| 3720 | + |
| 3721 | + # nested close |
| 3722 | + store = HDFStore(path,mode='w') |
| 3723 | + store.append('df',df) |
| 3724 | + |
| 3725 | + store2 = HDFStore(path) |
| 3726 | + store2.append('df2',df) |
| 3727 | + store2.close() |
| 3728 | + self.assert_('CLOSED' in str(store2)) |
| 3729 | + self.assert_(not store2.is_open) |
| 3730 | + |
| 3731 | + store.close() |
| 3732 | + self.assert_('CLOSED' in str(store)) |
| 3733 | + self.assert_(not store.is_open) |
| 3734 | + |
| 3735 | + # double closing |
| 3736 | + store = HDFStore(path,mode='w') |
| 3737 | + store.append('df', df) |
| 3738 | + |
| 3739 | + store2 = HDFStore(path) |
| 3740 | + store.close() |
| 3741 | + self.assert_('CLOSED' in str(store)) |
| 3742 | + self.assert_(not store.is_open) |
3729 | 3743 |
|
3730 |
| - store2.close() |
3731 |
| - self.assert_('CLOSED' in str(store2)) |
3732 |
| - self.assert_(not store2.is_open) |
| 3744 | + store2.close() |
| 3745 | + self.assert_('CLOSED' in str(store2)) |
| 3746 | + self.assert_(not store2.is_open) |
3733 | 3747 |
|
3734 | 3748 | # ops on a closed store
|
3735 | 3749 | with ensure_clean_path(self.path) as path:
|
|
0 commit comments