示例#1
0
 def test_items_deprecation(self):
     registry = IsoRegistry(load_standard_modules=False)
     with warnings.catch_warnings(record=True) as w:
         # Cause all warnings to always be triggered.
         warnings.simplefilter("always")
         # Trigger a warning.
         registry.items()
         # Verify some things
         self.assertEqual(len(w), 1)
         warning = w[0]
         self.assertTrue(issubclass(warning.category, DeprecationWarning))
         self.assertIn("deprecated", str(warning.message))
示例#2
0
 def test_get_calendar_class(self):
     registry = IsoRegistry(load_standard_modules=False)
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     calendar_class = registry.get_calendar_class('RE')
     self.assertEqual(calendar_class, RegionCalendar)
     # Subregion
     calendar_class = registry.get_calendar_class('RE-SR')
     self.assertEqual(calendar_class, SubRegionCalendar)
     # Unknown code/region
     self.assertIsNone(registry.get_calendar_class('XX'))
示例#3
0
 def test_get_calendars_empty_arg(self):
     registry = IsoRegistry(load_standard_modules=False)
     # 3 regions, one sub-region
     registry.register('RE', self.region)
     registry.register('RE2', self.region)
     registry.register('RE3', self.region)
     registry.register('RE-SR', self.subregion)
     # Empty arg, no subregions
     calendars = registry.get_calendars([], include_subregions=False)
     self.assertEqual(len(calendars), 3)
     self.assertEqual(set({"RE", "RE2", "RE3"}), set(calendars.keys()))
     # Empty arg, with subregions
     calendars = registry.get_calendars([], include_subregions=True)
     self.assertEqual(len(calendars), 4)
     self.assertEqual(set({"RE", "RE2", "RE3", "RE-SR"}),
                      set(calendars.keys()))
示例#4
0
    def test_get_calendars_no_arg(self):
        registry = IsoRegistry(load_standard_modules=False)
        # 3 regions, one sub-region
        registry.register('RE', self.region)
        registry.register('RE2', self.region)
        registry.register('RE3', self.region)
        registry.register('RE-SR', self.subregion)

        # Should be equivalent to [] + no subregions
        calendars = registry.get_calendars()
        self.assertEqual(len(calendars), 3)
        self.assertEqual(set({"RE", "RE2", "RE3"}), set(calendars.keys()))

        # Should be equivalent to [] + include subregions
        calendars = registry.items(include_subregions=True)
        self.assertEqual(len(calendars), 4)
        self.assertEqual(set({"RE", "RE2", "RE3", "RE-SR"}),
                         set(calendars.keys()))
示例#5
0
 def test_get_subregions(self):
     registry = IsoRegistry(load_standard_modules=False)
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     registry.register('OR-SR', self.subregion)
     subregions = registry.get_subregions('RE')
     self.assertIn('RE-SR', subregions)
     self.assertEqual(1, len(subregions))
示例#6
0
 def test_get_subregions(self):
     registry = IsoRegistry()
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     registry.register('OR-SR', self.subregion)
     subregions = registry.get_subregions('RE')
     self.assertIn('RE-SR', subregions)
     self.assertEqual(1, len(subregions))
示例#7
0
 def test_get_items(self):
     registry = IsoRegistry(load_standard_modules=False)
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     registry.register('OR-SR', self.subregion)
     items = registry.items(['RE'], include_subregions=True)
     self.assertEqual(2, len(items))
     self.assertIn('RE', items)
     self.assertIn('RE-SR', items)
     items = registry.items(['RE'], include_subregions=False)
     self.assertEqual(1, len(items))
     self.assertIn('RE', items)
示例#8
0
 def test_get_subregions(self):
     registry = IsoRegistry()
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     registry.register('OR-SR', self.subregion)
     subregions = registry.get_subregions('RE')
     self.assertIn('RE-SR', subregions)
     self.assertEqual(1, len(subregions))
示例#9
0
 def test_get_items(self):
     registry = IsoRegistry()
     registry.register('RE', self.region)
     registry.register('RE-SR', self.subregion)
     registry.register('OR-SR', self.subregion)
     items = registry.items(['RE'], include_subregions=True)
     self.assertEqual(2, len(items))
     self.assertIn('RE', items)
     self.assertIn('RE-SR', items)
     items = registry.items(['RE'], include_subregions=False)
     self.assertEqual(1, len(items))
     self.assertIn('RE', items)
示例#10
0
 def test_get_calendar_class(self):
     registry = IsoRegistry(load_standard_modules=False)
     registry.register('RE', self.region)
     calendar_class = registry.get_calendar_class('RE')
     self.assertEqual(calendar_class, RegionCalendar)
示例#11
0
 def test_register(self):
     registry = IsoRegistry(load_standard_modules=False)
     self.assertEqual(0, len(registry.region_registry.items()))
     registry.register('RE', self.region)
     self.assertEqual(1, len(registry.region_registry.items()))
     self.assertEqual(RegionCalendar, registry.region_registry['RE'])
示例#12
0
 def test_get_calendar_class(self):
     registry = IsoRegistry()
     registry.register('RE', self.region)
     calendar_class = registry.get_calendar_class('RE')
     self.assertEqual(calendar_class, RegionCalendar)
示例#13
0
 def test_get_calendar_class(self):
     registry = IsoRegistry()
     registry.register('RE', self.region)
     calendar_class = registry.get_calendar_class('RE')
     self.assertEqual(calendar_class, RegionCalendar)
示例#14
0
    def test_get_calendars_with_subregions(self):
        registry = IsoRegistry(load_standard_modules=False)
        registry.register('RE', self.region)
        registry.register('RE2', self.region)
        registry.register('RE-SR', self.subregion)
        calendars = registry.get_calendars(['RE2', "RE-SR"],
                                           include_subregions=True)
        self.assertEqual(2, len(calendars))
        self.assertIn('RE2', calendars)
        self.assertIn('RE-SR', calendars)
        calendars = registry.get_calendars(['RE2', "RE-SR"],
                                           include_subregions=False)
        self.assertEqual(2, len(calendars))
        self.assertIn('RE2', calendars)
        self.assertIn('RE-SR', calendars)

        # Only a subregion
        calendars = registry.get_calendars(["RE-SR"], include_subregions=True)
        self.assertEqual(1, len(calendars))
        self.assertIn('RE-SR', calendars)
示例#15
0
 def test_get_calendars_unknown(self):
     registry = IsoRegistry(load_standard_modules=False)
     registry.register('RE', self.region)
     calendars = registry.get_calendars(['XX'])
     self.assertEqual(calendars, {})
示例#16
0
 def test_register(self):
     registry = IsoRegistry()
     self.assertEqual(0, len(registry.region_registry.items()))
     registry.register('RE', self.region)
     self.assertEqual(1, len(registry.region_registry.items()))
     self.assertEqual(RegionCalendar, registry.region_registry['RE'])
示例#17
0
 def test_register_non_calendar(self):
     registry = IsoRegistry(load_standard_modules=False)
     with self.assertRaises(ISORegistryError):
         registry.register("NAC", NotACalendarClass)
示例#18
0
 def test_register(self):
     registry = IsoRegistry()
     self.assertEqual(0, len(registry.region_registry.items()))
     registry.register('RE', self.region)
     self.assertEqual(1, len(registry.region_registry.items()))
     self.assertEqual(RegionCalendar, registry.region_registry['RE'])