Esempio n. 1
0
 def test_save_data_input_text(self):
     a = InputFileLoaderCheckerSaver()
     a._input_text= "hello"
     a.save_data_to_file=True
     a._save_data()
     assert_equal(self.tempdir.read(
             ('out0002','out0002_input_original.py'), 'utf-8').strip().splitlines(),
                  'hello'.splitlines())
Esempio n. 2
0
    def test_determine_output_stem_directory(self):
        a = InputFileLoaderCheckerSaver()
        a.directory = os.path.join(self.tempdir.path, 'what')
        a._determine_output_stem()

        assert_equal(
            a._file_stem,
            os.path.join(self.tempdir.path, 'what', 'out0002', 'out0002'))
Esempio n. 3
0
    def test_check_zero_or_all(self):
        a = InputFileLoaderCheckerSaver()
        a.a=4
        a.b=6
        a.c=None
        a._zero_or_all = ['a b c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Esempio n. 4
0
    def test_save_data_grid_data_dicts(self):
        a = InputFileLoaderCheckerSaver()
        a._grid_data_dicts= {'data': np.arange(6).reshape(3,2)}
        a.save_data_to_file=True
        a._save_data()

#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002.csv')))
Esempio n. 5
0
    def test_attribute_defaults(self):
        a = InputFileLoaderCheckerSaver()
        a._input_text = 'b=6'
        a._attributes = "a b".split()
        a._attribute_defaults = {'a': 24}
        a._initialize_attributes()
        a._transfer_attributes_from_inputfile()

        assert_equal(a.a, 24)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'b=6')
Esempio n. 6
0
    def test_attribute_defaults(self):
        a = InputFileLoaderCheckerSaver()
        a._input_text = 'b=6'
        a._attributes = "a b".split()
        a._attribute_defaults = {'a': 24}
        a._initialize_attributes()
        a._transfer_attributes_from_inputfile()

        assert_equal(a.a, 24)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'b=6')
Esempio n. 7
0
    def test_check_attributes_to_force_same_len(self):
        a = InputFileLoaderCheckerSaver()
        a.a = [4, 5]
        a.c = None
        a._attributes_to_force_same_len = ['a c'.split()]
        a.check_input_attributes()

        assert_equal(a.c, [None, None])
Esempio n. 8
0
    def test_check_attributes_that_should_be_lists(self):
        a = InputFileLoaderCheckerSaver()
        a.a = 4
        a.b = 6
        a._attributes_that_should_be_lists = ['b']
        a.check_input_attributes()

        assert_equal(a.a, 4)
        assert_equal(a.b, [6])
Esempio n. 9
0
    def test_init_from_str(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b".split()
        a._initialize_attributes()
        a.__init__('a=4\nb=6')

        assert_equal(a.a, 4)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'a=4\nb=6')
Esempio n. 10
0
    def test_save_data_input_ext(self):
        a = InputFileLoaderCheckerSaver()
        a._input_text= "hello"
        a.input_ext= '.txt'
        a.save_data_to_file=True
        a._save_data()

        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002_input_original.txt')))
Esempio n. 11
0
    def test_init_from_fileobj(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b".split()
        a._initialize_attributes()
        with open(os.path.join(self.tempdir.path, 'inp1.py'), 'r') as f:
            a.__init__(f)

        assert_equal(a.a, 4)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'a=4\nb=6')
Esempio n. 12
0
    def test_save_data_grid_data_dicts_data_ext(self):
        a = InputFileLoaderCheckerSaver()
        a._grid_data_dicts= {'data': np.arange(6).reshape(3,2)}
        a.save_data_to_file=True
        a.data_ext = ".txt"
        a._save_data()

#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002.txt')))
Esempio n. 13
0
    def test_save_data_parsed(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b ".split()
        a.save_data_to_file=True
#        a._initialize_attributes()
        a.a=4
        a.b=6

        a._save_data()
#        print(os.listdir(self.tempdir.path))
#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        assert_equal(self.tempdir.read(
                ('out0002','out0002_input_parsed.py'), 'utf-8').strip().splitlines(),
                     'a = 4\nb = 6'.splitlines())
Esempio n. 14
0
    def test_check_attributes_to_force_same_len(self):
        a = InputFileLoaderCheckerSaver()
        a.a = [4,5]
        a.c=None
        a._attributes_to_force_same_len = ['a c'.split()]
        a.check_input_attributes()

        assert_equal(a.c, [None, None])
Esempio n. 15
0
    def test_check_zero_or_all(self):
        a = InputFileLoaderCheckerSaver()
        a.a = 4
        a.b = 6
        a.c = None
        a._zero_or_all = ['a b c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Esempio n. 16
0
 def test_save_data_input_text(self):
     a = InputFileLoaderCheckerSaver()
     a._input_text= "hello"
     a.save_data_to_file=True
     a._save_data()
     assert_equal(self.tempdir.read(
             ('out0002','out0002_input_original.py'), 'utf-8').strip().splitlines(),
                  'hello'.splitlines())
Esempio n. 17
0
    def test_save_figures_figure_ext(self):
        a = InputFileLoaderCheckerSaver()
        a.save_figures_to_file=True
        a.figure_ext='.pdf'

        fig = matplotlib.pyplot.figure()
        ax = fig.add_subplot('111')
        ax.plot(4,5)
        fig.set_label('sing')
        a._figures=[fig]
        a._save_figures()
        a._figures=None
        matplotlib.pyplot.clf()
#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002_sing.pdf')))
Esempio n. 18
0
    def test_init_from_str(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b".split()
        a._initialize_attributes()
        a.__init__('a=4\nb=6')

        assert_equal(a.a, 4)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'a=4\nb=6')
Esempio n. 19
0
    def test_check_attributes_that_should_be_lists(self):
        a = InputFileLoaderCheckerSaver()
        a.a=4
        a.b=6
        a._attributes_that_should_be_lists = ['b']
        a.check_input_attributes()

        assert_equal(a.a, 4)
        assert_equal(a.b, [6])
Esempio n. 20
0
    def test_save_data_input_ext(self):
        a = InputFileLoaderCheckerSaver()
        a._input_text= "hello"
        a.input_ext= '.txt'
        a.save_data_to_file=True
        a._save_data()

        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002_input_original.txt')))
Esempio n. 21
0
    def test_init_from_fileobj(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b".split()
        a._initialize_attributes()
        with open(os.path.join(self.tempdir.path, 'inp1.py'), 'r') as f:
            a.__init__(f)

        assert_equal(a.a, 4)
        assert_equal(a.b, 6)
        assert_equal(a._input_text, 'a=4\nb=6')
Esempio n. 22
0
    def test_save_data_parsed(self):
        a = InputFileLoaderCheckerSaver()
        a._attributes = "a b ".split()
        a.save_data_to_file=True
#        a._initialize_attributes()
        a.a=4
        a.b=6

        a._save_data()
#        print(os.listdir(self.tempdir.path))
#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        assert_equal(self.tempdir.read(
                ('out0002','out0002_input_parsed.py'), 'utf-8').strip().splitlines(),
                     'a = 4\nb = 6'.splitlines())
Esempio n. 23
0
    def test_save_figures_figure_ext(self):
        a = InputFileLoaderCheckerSaver()
        a.save_figures_to_file=True
        a.figure_ext='.pdf'

        fig = matplotlib.pyplot.figure()
        ax = fig.add_subplot('111')
        ax.plot(4,5)
        fig.set_label('sing')
        a._figures=[fig]
        a._save_figures()
        a._figures=None
        matplotlib.pyplot.clf()
#        print(os.listdir(os.path.join(self.tempdir.path,'out0002')))
        ok_(os.path.isfile(os.path.join(
            self.tempdir.path, 'out0002','out0002_sing.pdf')))
Esempio n. 24
0
 def test_check_attributes_that_should_have_same_len_pairs(self):
     a = InputFileLoaderCheckerSaver()
     a.a = [2, 3]
     a.c = [3]
     a._attributes_that_should_have_same_len_pairs = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 25
0
 def test_check_attributes_that_should_have_same_x_limits(self):
     a = InputFileLoaderCheckerSaver()
     a.a = PolyLine([0, 1], [2, 5])
     a.c = PolyLine([0, 7], [5, 6])
     a._attributes_that_should_have_same_x_limits = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 26
0
 def test_determine_output_stem_create_directory(self):
     a = InputFileLoaderCheckerSaver()
     a.create_directory = False
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\out0002')
Esempio n. 27
0
 def test_determine_output_stem_create_directory(self):
     a = InputFileLoaderCheckerSaver()
     a.create_directory = False
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\out0002')
Esempio n. 28
0
 def test_check_attributes_that_should_have_same_x_limits(self):
     a = InputFileLoaderCheckerSaver()
     a.a = PolyLine([0,1], [2,5])
     a.c = PolyLine([0,7], [5,6])
     a._attributes_that_should_have_same_x_limits = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 29
0
 def test_check_attributes_that_should_have_same_len_pairs(self):
     a = InputFileLoaderCheckerSaver()
     a.a = [2, 3]
     a.c = [3]
     a._attributes_that_should_have_same_len_pairs = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 30
0
    def test_determine_output_stem_defaults(self):
        a = InputFileLoaderCheckerSaver()
        a._determine_output_stem()

        assert_equal(a._file_stem, '.\\out0002\\out0002')
Esempio n. 31
0
 def test_determine_output_stem_prefix(self):
     a = InputFileLoaderCheckerSaver()
     a.prefix = 'hello_'
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\hello_0001\\hello_0001')
Esempio n. 32
0
    def test_determine_output_stem_defaults(self):
        a = InputFileLoaderCheckerSaver()
        a._determine_output_stem()

        assert_equal(a._file_stem, '.\\out0002\\out0002')
Esempio n. 33
0
 def test_determine_output_stem_overwrite(self):
     a = InputFileLoaderCheckerSaver()
     a.overwrite = True
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\out0001\\out0001')
Esempio n. 34
0
 def test_check_one_implies_others(self):
     a = InputFileLoaderCheckerSaver()
     a.a = 4
     a.c=None
     a._one_implies_others = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 35
0
 def test_determine_output_stem_prefix(self):
     a = InputFileLoaderCheckerSaver()
     a.prefix = 'hello_'
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\hello_0001\\hello_0001')
Esempio n. 36
0
    def test_check_at_least_one(self):
        a = InputFileLoaderCheckerSaver()
        a.c=None
        a._at_least_one = ['c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Esempio n. 37
0
    def test_check_at_least_one(self):
        a = InputFileLoaderCheckerSaver()
        a.c = None
        a._at_least_one = ['c'.split()]

        assert_raises(ValueError, a.check_input_attributes)
Esempio n. 38
0
 def test_check_one_implies_others(self):
     a = InputFileLoaderCheckerSaver()
     a.a = 4
     a.c = None
     a._one_implies_others = ['a c'.split()]
     assert_raises(ValueError, a.check_input_attributes)
Esempio n. 39
0
    def test_determine_output_stem_directory(self):
        a = InputFileLoaderCheckerSaver()
        a.directory = os.path.join(self.tempdir.path, 'what')
        a._determine_output_stem()

        assert_equal(a._file_stem, os.path.join(self.tempdir.path,'what', 'out0002', 'out0002'))
Esempio n. 40
0
 def test_determine_output_stem_overwrite(self):
     a = InputFileLoaderCheckerSaver()
     a.overwrite = True
     a._determine_output_stem()
     assert_equal(a._file_stem, '.\\out0001\\out0001')